MongoDb error caused by a big result set

658 Views Asked by At

I m actually facing a problem when trying to get a full resultset (~40 result). Each object has ~260 childs references and other objects packed in.

Actually, when I try to display 30 objects, it works. But when I try with 40 it doesn't. Each object is correct, no data is invalid.

It seems that I've exceed the maximum size(4 or 16 mb) authorized by mongoDb or defaultly Mongoskin (the library that I use to access mongodb), and mongodb close the pool connection to my application.

So how can I increase the maximum document size, or the maximum result set size, to display everything I need ?

EDIT : My collection size is 8Mb (from MongoVue informations)

EDIT 2 : The code I use to get my data :

db.collection("roadmap").find({}).toArray()

An screenshot of my db : enter image description here

EDIT 3 : I changed the way I was exploiting my data using

@em.collection('roadmap').find({}, (err, resultCursor)=>
      nextItem = (err, item)=>
        if !item)
          return

        console.log item
        resultCursor.nextObject(nextItem)
      resultCursor.nextObject(nextItem)
    )

It doesn't work neither, the request is executed, and then, I lose my mongodb connection. If I comment this piece of code in my application, all is working great.

EDIT 4 : Full stack trace, it's more a library problem than a db problem

Error: parseError occured
  at [object Object].<anonymous> (/var/www/xxxxxx/Ws/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:192:34)
  at [object Object].emit (events.js:98:17)
  at Socket.<anonymous> (/var/www/xxxxxx/Ws/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection.js:393:20)
  at Socket.emit (events.js:95:17)
  at Socket.<anonymous> (_stream_readable.js:764:14)
  at Socket.emit (events.js:92:17)
  at emitReadable_ (_stream_readable.js:426:10)
  at emitReadable (_stream_readable.js:422:5)
  at readableAddChunk (_stream_readable.js:165:9)
  at Socket.Readable.push (_stream_readable.js:127:10)
2

There are 2 best solutions below

5
On

I would suggest you to Create and index for the collection 'roadmap'.

 db.roadmap.ensureIndex({zone:1});

This is just used to retrive data faster than before, refer http://docs.mongodb.org/manual/core/indexes-introduction/

Change the Find as follows, there is no need of toArray function since the data is already an array.

 db.roadmap.find({},function(err,data){
 if(err){
 console.log(err);
}
console.log(data); 
)

This finds all the data in the roadmap collection.The index is used when the data set is huge. Hope this helps.

3
On

That error is being emitted by the mongo node driver "below" mongoskin. In the connection file, there are several places that can emit this error. To see the actual error, give the connection a logger and it will print the thing. That will tell you where in the connection you have a problem, and what it is. Note that mongoskin is using version 1.4.4 of the driver, so if it is a bug they might have fixed it.