I'm not 100% percent if this is possible, but i think it should be.
I want to update a document so that a field (END) is inserted into an array (INTERMISSIONS). I think im quite close to achieving it, but i either get an error or insert the string "$END".
The two queries i have are :
db.myCollection.findOneAndUpdate(
{"_id" : new ObjectId("...")},
{ '$push' : {'INTERMISSIONS' : '$END' } }
)
This one completes without errors, but instead of the $END value just "$END" is inserted
db.myCollection.findOneAndUpdate(
{"_id" : new ObjectId("...")},
{ '$push' :
{'INTERMISSIONS' : {$first:"$END" }}
}
)
Here i tried to "force" mongo to recognise $END as a field, but i instead get the error The dollar ($) prefixed field '$first' in 'INTERMISSIONS..START.$first' is not valid for storage.
The document structure is the following
{
"_id" : ObjectId("5f7dabb9c02c0000d2003ec2"),
"USUARIO" : "admin",
"START" : ISODate("2020-10-07T11:51:21Z"),
"INTERMISSIONS" : [ ],
"END" : ISODate("2020-10-08T09:39:27Z")
}