In Node.js, Collection.insert does not return null

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Environment:
      Node.js
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Collection.insert documentation at http://mongodb.github.io/node-mongodb-native/api-generated/collection.html#insert states it returns null ("Returns: null"). In fact, it returns the collection. The significance is the fact that code can be chained.

      var mongo = require('mongodb');
      var assert = require('assert');
      var server = new mongo.Server('localhost', 27017,

      {auto_reconnect: true}

      );
      var db = new mongo.Db('dbnameGoesHere', server,

      {w: 1, j: true}

      );

      db.open(function(err, db) {
      var collection = db.collection('collectionNameGoesHere');
      var result = collection.insert({}, function(err, doc)

      { assert.equal(arguments.length, 2); // close event-loop db.close(); }

      );
      assert(result instanceof mongo.Collection);
      });

            Assignee:
            Unassigned
            Reporter:
            Harry Pehkonen
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: