Nikita Massalitin
Nikita Massalitin

Reputation: 83

Why mongodb not giving me more than 100 documents?

Why does my query not working with more than 100 documents in collection?

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

err says this:

name: 'MongoError',
message: 'connection destroyed, not possible to instantiate cursor'

If documents <100 all works fine.

Upvotes: 8

Views: 4315

Answers (2)

T.Todua
T.Todua

Reputation: 56351

in source there is written:

MongoDB supports no more than 100 levels of nesting for BSON documents.

maybe you look into : Mongo and find always limited to 100 with geo data

Upvotes: -3

robertklep
robertklep

Reputation: 203231

You're probably doing something like this:

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

So you're closing the database before the callback to toArray has been called (although it may work on some occassions).

Instead, try this:

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

Upvotes: 23

Related Questions