db.test.insertOne({a: new Date()});
db.test.insertOne({a: {"$date": {"$numberLong": "1706205816000"}}});
db.test.find();
{
_id: ObjectId('65b2a243061433116eb4f3c2'),
a: 2024-01-25T18:02:43.966Z
}
{
_id: ObjectId('65b2a27d061433116eb4f3c3'),
a: 2024-01-25T18:03:36.000Z }
db.test.aggregate({$project: {d: {$subtract: ["$a", "$a"]}}}) - fails with
MongoServerError: PlanExecutor error during aggregation :: caused by :: Only numbers and dates are allowed in an $subtract expression
db.test.deleteOne({_id: ObjectId('65b2a27d061433116eb4f3c3')}); db.test.aggregate({$project: {d: {$subtract: ["$a", "$a"]}}}) - works
{
_id: ObjectId('65b2a243061433116eb4f3c2'),
d: 0
}