Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-13862

Agg date expressions don't allow expressions to resolve to argument list

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: manual, Server
    • Labels:
      None

      Description

      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:

      {date: X, timestamp: Y}

      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 :
      

      Scope of changes

      Impact to Other Docs

      MVP (Work and Date)

      Resources (Scope or Design Docs, Invision, etc.)

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            george.wangensteen George Wangensteen
            Participants:
            Last commenter:
            Jeffrey Allen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Days since reply:
              7 weeks ago