0

I have document structure

{
    "Name" : "MongoDB",
    "Client" : "Database",
    "Details" : [ 
        {
            "Date" : "2018-07-18",
            "Code" : {
                "new" : "5",
                "new 1" : "3",
                "new 2" : "4"
            }
        }, 
        {
            "Date" : "2018-07-19",
            "Code" : {
                "new" : "7",
                "new 2" : "4"
            }
        }
  ]
}

I want to update the field "new":"5" as "Devops":"2, Based on "Name":"Mongodb","Date":"2018-07-18".

Andrei Suvorkov
  • 5,559
  • 5
  • 22
  • 48
plnr
  • 1

1 Answers1

0

I tried this in Java,but this code appends the new document for the same date

Bson filter =new Document("Name",name);

    Document h=new Document();
    Document dd=new Document();
    for(int i=0;i<ccode.length;i++)
      {
        h.append(ccode[i], hour[i]);
      }
     dd.append("Date", d);
     dd.append("Code", h);
    Document doc=new Document().append("Details",dd);
    System.out.println(dd);
    Bson updateOperationDocument = new Document("$push", doc);
    collection.updateOne(filter, updateOperationDocument);
kanthri k
  • 1
  • 2