(MongoDB Java) $push into array
DBObject listItem = new BasicDBObject(“scores”, new BasicDBObject(“type”,”quiz”).append(“score”,99)); DBObject updateQuery = new BasicDBObject(“$push”, listItem); myCol.update(findQuery, updateQuery);
DBObject listItem = new BasicDBObject(“scores”, new BasicDBObject(“type”,”quiz”).append(“score”,99)); DBObject updateQuery = new BasicDBObject(“$push”, listItem); myCol.update(findQuery, updateQuery);
I don’t know Java driver, but do you have to create a list there? What happens if you try this code? BasicDBObject update = new BasicDBObject().append(“$push”, new BasicDBObject().append(“values”, dboVital)); update = update.append(“$set”, new BasicDBObject().append(“endTime”, time)); collection.update( new BasicDBObject().append(“_id”, pageId), update, true, false); This should produce the equivalent of db.collection.update({_id: pageId}, {$push: {values: dboVital}, $set: {endTime: … Read more