mongodb upsert from java: how to get _id of existing object? -
i'm using mongo-jackson-wrapper java , mongodb. find object querying field of mine (not _id field), , need know _id field value, whether net result update or insert. however, exception:
com.mongodb.mongoexception: no objects return @ net.vz.mongodb.jackson.writeresult.getsavedid(writeresult.java:97) the exception comes wrapper, not mongodb driver itself.
writeresult<entitydocument, string> wr = coll.update(dbquery.is("corefentityid", corefentityid), up, true, false); what (if anything) right way this?
you need use findandmodify , set returnnew true
you can view javadoc
this code should trick haven't tested it.
coll.findandmodify(dbquery.is("corefentityid", corefentityid), null, null, false, up, true, false);
Comments
Post a Comment