Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 545
Nikita Massalitin Avatar asked Sep 16 '16 15:09

Nikita Massalitin


People also ask

How many documents can MongoDB handle?

Mongo can easily handle billions of documents and can have billions of documents in the one collection but remember that the maximum document size is 16mb. There are many folk with billions of documents in MongoDB and there's lots of discussions about it on the MongoDB Google User Group.

Does MongoDB have a limit?

The maximum size an individual document can be in MongoDB is 16MB with a nested depth of 100 levels. Edit: There is no max size for an individual MongoDB database.

How does MongoDB define maximum number of documents in collection?

Unless you create a capped collection, there is no limit to the number of documents in a collection. There is a 16MB limit to the size of a document (use gridfs in this situation) and limits in the storage engine for the size of the database and data.


1 Answers

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();
});
like image 98
robertklep Avatar answered Oct 02 '22 18:10

robertklep