I have the following schema in my mongo document:
{
//more stuff
arrayExample:[
{
//more stuff as well
field1: "foo"
},
{
//more stuff as well
field1: "foo"
},
{
//more stuff as well
field1: "foo"
},
//...
]
}
What I want to do is add a field id: ObjectId() to each element inside the arrayExample so I could have something like follows:
{
//more stuff
arrayExample:[
{
//more stuff as well
field1: "foo",
id: 1
},
{
//more stuff as well
field1: "foo",
id: 2
},
{
//more stuff as well
field1: "foo",
id: 3
},
//...
]
}
I tried to do this with an aggregation using map but it didn't work the way I did it. Is there a way to do this? thank you very much