How to update value of specific embedded document, inside an array, of a specific document in MongoDB?

Here is RameshVel’s solution translated to java: DB db = conn.getDB( “yourDB” ); DBCollection coll = db.getCollection( “yourCollection” ); ObjectId _id = new ObjectId(“4e71b07ff391f2b283be2f95”); ObjectId arrayId = new ObjectId(“4e639a918dca838d4575979c”); BasicDBObject query = new BasicDBObject(); query.put(“_id”, _id); query.put(“array._arrayId”, arrayId); BasicDBObject data = new BasicDBObject(); data.put(“array.$.someField”, “updated”); BasicDBObject command = new BasicDBObject(); command.put(“$set”, data); coll.update(query, command);

How to insert multiple documents at once in MongoDB through Java

DBCollection.insert accepts a parameter of type DBObject, List<DBObject> or an array of DBObjects for inserting multiple documents at once. You are passing in a string array. You must manually populate documents(DBObjects), insert them to a List<DBObject> or an array of DBObjects and eventually insert them. DBObject document1 = new BasicDBObject(); document1.put(“name”, “Kiran”); document1.put(“age”, 20); DBObject … Read more

Case insensitive sorting in MongoDB

Update: As of now mongodb have case insensitive indexes: Users.find({}) .collation({locale: “en” }) .sort({name: 1}) .exec() .then(…) shell: db.getCollection(‘users’) .find({}) .collation({‘locale’:’en’}) .sort({‘firstName’:1}) Update: This answer is out of date, 3.4 will have case insensitive indexes. Look to the JIRA for more information https://jira.mongodb.org/browse/SERVER-90 Unfortunately MongoDB does not yet have case insensitive indexes: https://jira.mongodb.org/browse/SERVER-90 and the … Read more