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);


}
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
  • So what is the problem? – Neil Lunn May 21 '18 at 10:53
  • iam not getting output after running my programm, – Sidda Reddy May 21 '18 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. – Neil Lunn May 21 '18 at 11:27

0 Answers0