Home:ALL Converter>Mongoose/MongoDB how to query nested documents as a single array

Mongoose/MongoDB how to query nested documents as a single array

Ask Time:2016-10-15T22:53:35         Author:Xsmael

Json Formatter

one item in the collection looks as shown below.

{
"_id" : ObjectId("4f7ee46e08403d063ab0b4f9"),
"name" : "MongoDB",
"notes" : [
            {
              "title" : "Hello MongoDB",
              "content" : "Hello MongoDB"
            },
            {
              "title" : "ReplicaSet MongoDB",
              "content" : "ReplicaSet MongoDB"
            }
         ]
}

lets say i want to retrieve all the notes of all documents as a single array, how should i wite my query? give mongoose and or mongoDB example

Author:Xsmael,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/40060502/mongoose-mongodb-how-to-query-nested-documents-as-a-single-array
yy