I'm currently using aggregate operator to return documents that has an array of embedded (sub) documents. I want to rename the field name for the array and also rename fields names in the embedded documents of the array.
As an example, for projection I want to rename the array from "friends" to "buddies" and I also want to rename fields in the embedded document from "name" to "nickName". Can I do this within an aggregate operation and if so how?
Here's an example of the source document:
[
{
_id: ObjectID,
name: 'Matthew',
friends: [
{name: 'Slim', age: '32'},
{name: 'buba', age: '36'}
]
}
]
Here's what the results should look like:
[
{
_id: ObjectID,
name: 'Matthew',
buddies: [
{nickName: 'Chris', age: '32'},
{nickName: 'Jim', age: '36'}
]
}
]
Thanks for the help in advance.