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
Post a Comment