Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useObjectId == false, but upserts generate ObjectId #97

Open
DieterDePaepe opened this issue Dec 17, 2016 · 4 comments
Open

useObjectId == false, but upserts generate ObjectId #97

DieterDePaepe opened this issue Dec 17, 2016 · 4 comments

Comments

@DieterDePaepe
Copy link

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 karianna added this to the 3.4.0 milestone Dec 19, 2016
@karianna
Copy link
Contributor

@johnoliver This works as intended?

@yh3434
Copy link

yh3434 commented Mar 15, 2017

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

@johnoliver
Copy link
Contributor

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.

@vietj vietj removed the to review label Dec 23, 2017
@karianna karianna modified the milestones: 3.x.x, 3.5.1 Dec 23, 2017
@HendrikLanghammer
Copy link

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]

@karianna karianna reopened this Jul 15, 2018
@karianna karianna removed this from the 3.5.1 milestone May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants