I have a collection that looks like this:
{
_id: ...,
checkins: [
{
id: ...,
createdAt: 1488052032,
...
},
{
id: ...,
createdAt: 1488052032,
...
}
]
}
I want to add a new element called created
next to the id and createdAt attributes (inside checkins, an array of objects). And I want to do it for all the elements that doesn't have this new element.
I know how to check if an object has already an attribute in it, but I am having some problems adding the element. I am using the code below and returns me an error saying: The positional operator did not find the match needed from the query.
db.profiles.updateMany(
{},
{$set: {"checkins.$.created": new Date(0)}}
)
Any ideas about what I am doing wrong?