L
L
lohmag2016-09-16 16:51:52
Node.js
lohmag, 2016-09-16 16:51:52

Why doesn't mongodb return more than 100 records?

Tell me why the query does not want to be executed if the table has more than 100 records, if 100 or less, everything is ok.

db.collection('allowedmacs').find().toArray(function(err, docs) {
console.log(docs);
}

err has this error:
name: 'MongoError',
message: 'connection destroyed, not possible to instantiate cursor'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Philipp, 2016-09-16
@zoonman

You need to use cursor here.

var findMacs = function(db, callback) {
   var cursor =db.collection('allowedmacs').find( );
   cursor.each(function(err, doc) {
      assert.equal(err, null);
      if (doc != null) {
         console.dir(doc);
      } else {
         callback();
      }
   });
};

MongoClient.connect(url, function(err, db) {
  assert.equal(null, err);
  findMacs(db, function() {
      db.close();
  });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question