when using :
MongoCollection<SomeEntity> gameCollection = database.getCollection("entities", SomeEntity.class);
gameCollection.findOneAndUpdate(filter, update, new FindOneAndUpdateOptions().upsert(true));
SomeEntityCodec's encode method is called with a context that returns encodingCollectibleDocument=false
See:
com.mongodb.MongoCollectionImpl : 374
toBsonDocument(update)
bson.toBsonDocument(documentClass, codecRegistry)
neither RawBsonDocument(wrapped, codec), nor BsonDocumentWrapper(wrappedDocument, encoder) takes into account the upsert flag(if it is true, it SHOULD be a encodingCollectibleDocument