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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -