I am creating a projection and am trying to figure out how to convert a mongoid to a timestamp IN THE projection. It is apparent that we can use .getTimestamp() to just get the timestamp of a mongoid, but I don't know how to make a new field in a projection. I tried this and it fails.
db.collection.aggregate(
[
{$unwind:
"$arrayToUnwind"
},
{$project:
{
timeOfId: "$_id".getTimeStamp()
}
},
]
)
Any help please?! I want to make an ISO timestamp out of this projection.
Thanks!
https://docs.mongodb.com/manual/reference/operator/aggregation/toDate/
db.movies.aggregate([
{
"$project":
{
"date": { $toDate: "$_id" }
}
}
])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With