M
M
Mertico2017-04-10 16:01:39
MongoDB
Mertico, 2017-04-10 16:01:39

How to update nested array of documents?

There is a collection with a trace structure

{
  "name": null,
  "stage": [{
    "name": null,
    "task": [{
      "name": null,
      "category": 1,
      "price": 1800,
      "value": 10
    }]
  }]
}

And schemas for it in mongoose
How to update stage? task? Add them?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
emp1re, 2017-04-10
@Mertico

How to update stage?

db.collection.update( { stage: { $elemMatch: { name: null } },
   { $set: { "stage.$.name" : "SomeAmazingName" } })

db.collection.update( { query },
   { { $push: { scores: object })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question