vert-x3 / vertx-mongo-client

Mongo Client for Eclipse Vert.x
http://vertx.io
Apache License 2.0
60 stars 99 forks source link

useObjectId == false, but upserts generate ObjectId #97

Open DieterDePaepe opened 7 years ago

DieterDePaepe commented 7 years ago

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.

karianna commented 7 years ago

@johnoliver This works as intended?

yh3434 commented 7 years ago

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

johnoliver commented 6 years ago

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.

HendrikLanghammer commented 6 years ago

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]