-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Labels:None
Description
Many agg date expressions, like $dayOfMonth, can take as argument either :
-An expression that resolves to a Date, Timestamp, or ObjectId
-A document that lists arguments with some particular syntax (like:
The docs currently say that these agg operators take just an expression, and then state: "The argument must be a valid expression that resolves to one of the following:
-A Date, a Timestamp, or an ObjectID.
-A document of the following form: ...."
However, they can't actually accept an expression that resolves to the document-of-arguments. The expression must resolve to either a Date, Timestamp, or ObjectID; the document-of-arguments can be provided instead of an expression.
For example:
MongoDB Enterprise > db.example.insert({a: { date: new Date("January 2, 1998") }}) WriteResult({ "nInserted" : 1 }) MongoDB Enterprise > db.example.find() { "_id" : ObjectId("5f4fed07a67c58f260e9a184"), "a" : { "date" : ISODate("1998-01-02T00:00:00Z") } } MongoDB Enterprise > db.example.aggregate( [ { $project: { day: { $dayOfMonth: "$a" } } } ] ) uncaught exception: Error: command failed: { "ok" : 0, "errmsg" : "PlanExecutor error during aggregation :: caused by :: can't convert from BSON type object to Date", "code" : 16006, "codeName" : "Location16006" } : aggregate failed :