vertx-mongo-client icon indicating copy to clipboard operation
vertx-mongo-client copied to clipboard

useObjectId == false, but upserts generate ObjectId

Open DieterDePaepe opened this issue 8 years ago • 4 comments

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.

DieterDePaepe avatar Dec 17 '16 21:12 DieterDePaepe

@johnoliver This works as intended?

karianna avatar Dec 19 '16 10:12 karianna

Hello,I also encountered this problem。Any idea on how to resolve this problem?

yh3434 avatar Mar 15 '17 01:03 yh3434

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.

johnoliver avatar Dec 21 '17 23:12 johnoliver

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]

HendrikLanghammer avatar Jul 15 '18 13:07 HendrikLanghammer