Hello,
I’m trying to get the values of the fields contained in a nested document.
My collection is called posts. The key of the nested document is “comments_full”. The keys of the values I want to project are “commenter_id”, “commenter_url” and “commenter_name”. Thus my query is:
db.posts.aggregate([{$project: {
"comments_full.commenter_id": 1,
"comments_full.commenter_url": 1,
"comments_full.commenter_name": 1,
"_id": 0
}}])
I get results like the following one:
{ "comments_full" : [ {
"commenter_id" : "xxxxxxxxxxxxxx",
"commenter_url" : "xxxxxxxxxxxxxxxxxx",
"commenter_name" : "zzzzzzzzzzzz"
},
{
"commenter_id" : "xxxxxxxxxxxxxx",
"commenter_url" : "xxxxxxxxxxxxxxxxxx",
"commenter_name" : "zzzzzzzzzzzz"
}
]
}
How can I get a result document like the following one, without the “comments_full” key?
{
"commenter_id" : "xxxxxxxxxxxxxx",
"commenter_url" : "xxxxxxxxxxxxxxxxxx",
"commenter_name" : "zzzzzzzzzzzz"
}
Thanks in advance for your help!
Best,
Miguel