private static Object toInternalKey(BsonDocument key) {
    if (key == null) {
      return null;
    }

    BsonValue value = key.get(Mongos.ID_FIELD_NAME);

    if (value == null) {
      return null;
    }

    if (value.isString()) {
      return value.asString().getValue();
    } else if (value.isSymbol()) {
      return value.asSymbol().getSymbol();
    } else if (value.isObjectId()) {
      return value.asObjectId().getValue();
    }

    // don't know what to do with this value
    // TODO reuse CodecRegistry
    return null;
  }
Convert document key (BSON) to entity ID. Currently only strings are supported.
This code needs to leverage existing CodecRegistry to correctly convert BSON value
into ID type.
criteria/mongo/src/org/immutables/criteria/mongo/MongoWatchEvent.java