Re: MongoDB Node.JS Driver: count of removed records

549 views
Skip to first unread message

Osmar Olivo

unread,
Oct 2, 2012, 4:48:24 PM10/2/12
to mongod...@googlegroups.com
Can you post your code? Or at least the remove command?

Also, in the options part of the remove call are you running with {safe: true}. In order for callbacks to work, you need to wait for a response from the server, and thus must be running using safe mode.

On Sunday, September 30, 2012 1:38:43 PM UTC-4, Emlyn Murphy wrote:
Hello all,

In the "MongoDB Node.JS Driver" manual here:


In the "removing records from collections" section, it states that:

"callback callback function that gets two parameters - an error object (if an error occured) and the count of removed records"

However, when I successfully remove records, I get "undefined" for both parameters to the callback.  Is there something I'm missing?

Thanks,
Emlyn

Kilian Ciuffolo

unread,
Nov 17, 2013, 12:44:44 AM11/17/13
to mongod...@googlegroups.com
Same thing here.

If you copy/paste the example (and you correct the typo) the callback assertion throws.

var Db = require('mongodb').Db,
    MongoClient = require('mongodb').MongoClient,
    Server = require('mongodb').Server,
    ReplSetServers = require('mongodb').ReplSetServers,
    ObjectID = require('mongodb').ObjectID,
    Binary = require('mongodb').Binary,
    GridStore = require('mongodb').GridStore,
    Grid = require('mongodb').Grid,
    Code = require('mongodb').Code,
    BSON = require('mongodb').pure().BSON,
    assert = require('assert');

var db = new Db('test', new Server('localhost', 27017));
// Establish connection to db
db.open(function(err, db) {

  // Fetch a collection to insert document into
  db.collection("remove_subset_of_documents_safe", function(err, collection) {

    // Insert a bunch of documents
    collection.insert([{a:1}, {b:2}], {w:1}, function(err, result) {
      assert.equal(null, err);

      // Remove all the document
      collection.remove({a:1}, {w:1}, function(err, numberOfRemovedDocs) {
        assert.equal(null, err);
        assert.equal(1, numberOfRemovedDocs);
        db.close();
      });
    });
  })
});
Reply all
Reply to author
Forward
0 new messages