My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

mongodb aggegation- project key in root to inside an object

Siraj abbas's photo
Siraj abbas
·Aug 4, 2017

Hi I have the following requirement.Somebody plz help me.

I am doing a mongodb aggregate operation for which my final data looks like below

{
 "data":{
},
  "subdata":[{}]
}

For some reason I would like to get the final result as

{
  "data":{
    "subdata":[{}]
  }
}

I tried several ways.It is not working as I expected.

PS:I am not using mongoose.