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

$documents stage can't be used on a collection-level aggregation

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: manual, Server

      The mongo server returns an error if we try to use the $documents stage as first stage of an aggregation run on a collection.

       

      Enterprise test> db.test.aggregate([ { $documents: [{ nb: [1, 2, 3] }] }, { $project: { total: { $sum: ["$nb"] } } }] )
      MongoServerError: '$documents' can only be run with {aggregate: 1}

      I suggest updating the Behavior section of the $documents page to say so. Especially since the error message from the server is not very clear for someone that ignore the meaning of {{

      {aggregate: 1}

      }}

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              16 weeks, 2 days ago