MongoDb's $set equivalent in its java Driver -


is there way in can modify value of 1 of keys in mongodb via java driver. tried out following:

somecollection.update(dbobject query, dbobject update); somecollection.findandmodify(dbobject query, dbobject update); 

but both functions replace queried document updated document. way update 1 of value of particular key in case of using $set in mongo shell.(apart making new document fields copied , 1 of fields updated).

i not java expert, seems following code fit needs:

basicdbobject set = new basicdbobject("$set", new basicdbobject("age", 10)); set.append("$set", new basicdbobject("name", "some name"); somecollection.update(somesearchquery, set); 

also @ this example.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -