I am trying to create a new Date value in a projection in a composite pipeline reaction.
I saw other examples when people create this in the mongo shell, for example:
db.runCommand({
"aggregate" : "collectionName", "pipeline": [
{ $project: { exampleDate: new Date() } }
]
})
The challenge lies in new Date(). With the reaction to the projection will be the project object:
Project( ("exampleDate", BSONValue) )
where BSONValue may be BSONString. But this leads to the fact that mongoDB ignores such a line, as the result will be:
{ "aggregate" : "collectionName", "pipeline": [ { $project: { exampleDate: "new Date()" } } ] }
Is there any way to paste new Date()without quotes?
PS: I also tried using BSONDateTime(0)
But this leads to:
{ $date: 0 }
What makes mongoDB raise an invalid statement exception $date.
source
share