Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1236

The aggregation example on the tutorial page should enumerate cursor

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.0.2
    • Affects Version/s: 3.0.0
    • Component/s: Docs
    • None

      The aggregation example code on
      http://mongodb.github.io/node-mongodb-native/3.0/tutorials/aggregation/#the-aggregation-pipeline
      Should show how to process the cursor returned instead of printing cursor object.

      const collection = db.collection( 'restaurants' );
        collection.aggregate(
            [ { '$match': { "borough": "Bronx" } },
              { '$unwind': '$categories'},
              { '$group': { '_id': "$categories", 'Bronx restaurants': { '$sum': 1 } } }
            ],
      	  function(err, results) {
              assert.equal(err, null);
              console.log(results)
              callback(results);
            }
        );
      

      For example, this should have shown:

      const collection = db.collection( 'restaurants' );
        collection.aggregate(
            [ { '$match': { "borough": "Bronx" } },
              { '$unwind': '$categories'},
              { '$group': { '_id': "$categories", 'Bronx restaurants': { '$sum': 1 } } }
            ],
      	  function(err, cursor) {
              assert.equal(err, null);
      
              cursor.toArray(function(err, document){
                  console.log(document);
              });
              callback(results);
            }
        );
      

            Assignee:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Reporter:
            wan.bachtiar@mongodb.com Wan Bachtiar
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: