A
A
AdelNorbiblio2019-11-04 22:28:41
MongoDB
AdelNorbiblio, 2019-11-04 22:28:41

How to update large nesting in Mongodb?

Adel Norberg, [11/04/19 9:15 PM]
Hello, I can't figure out how to update a document with multiple nestings. There is a document:

{
  name: 'Name document',
  subdocs: [
     { 
        name: 'Name subdoc',
        array: ['a', 'b', 'c']
     }
  ]
}

How to update via mongoose the element 'a' of the array of the subdocument 'Name subdoc'?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hokim, 2019-11-06
@rhino_o

db.collection.update(
   { "subdocs.name": 'Name subdoc' },
   { $set: { "subdocs.0.array.0" : "new value" } }
)

You can read a more detailed description in the documentation, and see other examples .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question