vertx-mongo-client
vertx-mongo-client copied to clipboard
useObjectId == false, but upserts generate ObjectId
The following code still generates an ObjectId for newly added elements, rather than the expected string id. I tried tracing the problem, but lost my way in the callback structures in the libraries.
JsonObject query = new JsonObject()
.put("a", "a");
JsonObject obj = new JsonObject()
.put("$set", new JsonObject().put("lasttime", 123));
UpdateOptions options = new UpdateOptions(true, false);
mongo.updateCollectionWithOptions("test", query, obj, options, res2 -> {});
> db.test.find()
{ "_id" : ObjectId("5855a3cc59e87872fea8c39f"), "a" : "a", "lasttime" : 123 }
Using version 3.3.3.
@johnoliver This works as intended?
Hello,I also encountered this problem。Any idea on how to resolve this problem?
I have submitted a fix for this, although to be honest I actually view this as a bug in mongos driver. It seems inconsistent on their part that inserts call JsonObjectCodec#generateIdIfAbsentFromDocument
if needed, however an upsert does not.
This fix causes ans exception if upsert results in insert and _id from query is a JsonObject
java.lang.ClassCastException: io.vertx.core.json.JsonObject cannot be cast to java.lang.CharSequence at io.vertx.core.json.JsonObject.getString(JsonObject.java:111) ~[vertx-core-3.5.3.jar:3.5.3] at io.vertx.ext.mongo.impl.MongoClientImpl.generateIdIfNeeded(MongoClientImpl.java:224) ~[vertx-mongo-client-3.5.3.jar:3.5.3] at io.vertx.ext.mongo.impl.MongoClientImpl.updateCollectionWithOptions(MongoClientImpl.java:202) ~[vertx-mongo-client-3.5.3.jar:3.5.3]