MongoDB Java Async Driver replaceOne doesn't seem to work -


i trying update document mongodb async java driver , code below,

// jsonstring string of "{_id=5715e426ed3522391f106e68, name=alex} final document document = document.parse(jsonstring);  document newdocument = document.append("status", "processing"); mongodbcollection.replaceone(document, newdocument, (updateresult, throwable) -> {               if (updateresult != null) {                  log.info("updated doc ::::::>>> " + newdocument.tojson());                  log.info("updated result ::::>> "+updateresult.tostring());               } else {                  throwable.printstacktrace();                  log.error(throwable.getmessage());               }    }); 

as per logging, see updated document below,

info: updated doc ::::::>>> { "_id" : { "$oid" : "5715e426ed3522391f106e68" }, "status":"processing"} info: updated result ::::>> acknowledgedupdateresult{matchedcount=0, modifiedcount=0, upsertedid=null} 

but when see collection via robmongo not see updated document , still shows old document. have double checked looking in same collection , there aren't exceptions. doing wrong here?

the problem here line:

document newdocument = document.append("status", "processing"); 

where "thought" assigning "new document copy", "also" modifies document object append field.

as such, query not match, indicated in output:

{matchedcount=0, modifiedcount=0, upsertedid=null}            // ^ right here! see 0 matched 

so want "clone". it's not straightforward document, can done "hacky" method:

document document = document.parse(jsonstring);  document newdocument = document.parse(document.tojson()).append("status","processing");  system.out.println(newdocument); system.out.println(document); 

now see newdocument contains addition, whilst document remains unaltered, not case current code, , why query not match update.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -