Here is the mongo DB document structure provided above in the image. There you can see we have got a xmlRequests array under pages array (Pages is array of objects). So each session has pages array containing some objects
What I want to do:
Let us say we have 10 documents with same structure as shown in the image above. I want the aggregate (unified) array of all the pages under all the sessions in one array. In simple words I want the pages array of all the sessions in one array. (Aggregate)
Like this:
{
pages : [] // array containing all the objects of request arrays under each session.
}
I need a one unified requests[ ] array containing all the requests of all the sessions in one single array. I tried using db.collection.aggregate([ ]) but I don't know how to get the nested values in a document and unify all of them in one single array of objects.
Mongo Code Snippet
{
"user": "abc",
"sessions": {
"12345": {
"pages": [
{
requests: [ {name: 'request1'}]
}
]
},
"23456": {
"pages": [
{
requests: [ {name: 'request1'}]
}
]
}
}
}
{
"user": "xyz",
"sessions": {
"12345": {
"pages": [
{
requests: [ {name: 'request1'}]
}
]
},
"23456": {
"pages": [
{
requests: [ {name: 'request1'}]
}
]
}
}
}
FETCH ALL REQUEST ARRAYS IN THE COLLECTION AND COMBINE THEM INTO ONE ARRAY
