0
package hellomongo;
import java.util.ArrayList;

import java.util.List;
import java.util.List;
import javax.management.Query;

import java.util.List
import org.bson.types.ObjectId;

public class Update {
  private final static String HOST = "localhost";
  private final static int PORT = 27017;
  public static void main(String args[]) {

  MongoClient mongoClient = new MongoClient(HOST, PORT);
  DB db = mongoClient.getDB("admin");
  DBCollection coll = db.getCollection("command");



  ArrayList<Document> docList = new ArrayList<Document>();
  docList.add(new Document().append("d", 4));

  Document push = new Document().append(
    "$push", new Document().append("cmd", 
      new Document().append("$each", docList).append("$position", 3)));

  coll.updateMany(new  Document().append("_id","5b02a14804ed7d6c3ca1c262"), push);


}
3
  • So what is the problem? Commented May 21, 2018 at 10:53
  • iam not getting output after running my programm, Commented May 21, 2018 at 11:24
  • What output? Nothing here is returning any output and I don't see what that has to do with updating. _id looks like a "string" here instead of an ObjectId, so you you mean it "does not update anything"? Probably because the document actually has an ObjectId in the primary key. Commented May 21, 2018 at 11:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.