requireNonNull(collection, "collection cannot be null");
requireNonNull(query, "query cannot be null");
requireNonNull(replace, "update cannot be null");
requireNonNull(options, "options cannot be null");
requireNonNull(resultHandler, "resultHandler cannot be null");
<BUG>boolean id = query.containsKey(ID_FIELD);
query = encodeKeyWhenUseObjectId(query);  //TODO: Need to write test for this and delete</BUG>
MongoCollection<JsonObject> coll = getCollection(collection, options.getWriteOption());
<BUG>Bson bquery = wrap(query);
coll.replaceOne(bquery, replace, mongoUpdateOptions(options), toMongoClientUpdateResult(resultHandler));
</BUG>
return this;

requireNonNull(collection, "collection cannot be null");
requireNonNull(document, "document cannot be null");
requireNonNull(resultHandler, "resultHandler cannot be null");
MongoCollection<JsonObject> coll = getCollection(collection, writeOption);
Object id = document.getValue(ID_FIELD);
if (id == null) {
coll.insertOne(document, convertCallback(resultHandler, wr -> useObjectId ? document.getJsonObject(ID_FIELD).getString(JsonObjectCodec.OID_FIELD) : document.getString(ID_FIELD)));
} else {
JsonObject filter = new JsonObject();
JsonObject encodedDocument = encodeKeyWhenUseObjectId(document);
filter.put(ID_FIELD, encodedDocument.getValue(ID_FIELD));
com.mongodb.client.model.UpdateOptions updateOptions = new com.mongodb.client.model.UpdateOptions()
.upsert(true);
coll.replaceOne(wrap(filter), encodedDocument, updateOptions, convertCallback(resultHandler, result -> null));
