Cursor is closed ?

351 views
Skip to first unread message

Mika Saari

unread,
Nov 30, 2016, 5:54:58 AM11/30/16
to node-mongodb-native
Hi,

  What could be reason for error below?

  Thanks a lot,
     -Mika

  MongoDB 3.2
  mongod 1-shard, 3-replicas (replicas each in different VM)
  mongod configsrv 3-replicas (repicas each in different VM)
  mongos 3 pieces (each router in different VM)
  NodeJS mongodb(2.2.11) and mongodb-core(2.0.13)


  MongoError: Cursor is closed
    at Function.MongoError.create (/home/manager/service/node_modules/mongodb-core/lib/error.js:31:11)
    at Cursor.skip (/home/manager/service/node_modules/mongodb/lib/cursor.js:623:102)
    at /home/manager/service/routes/system-ops.js:56:32
    at /home/manager/service/node_modules/async/dist/async.js:1156:9
    at replenish (/home/manager/service/node_modules/async/dist/async.js:1030:17)
    at iterateeCallback (/home/manager/service/node_modules/async/dist/async.js:1015:17)
    at /home/manager/service/node_modules/async/dist/async.js:988:16
    at /home/manager/service/node_modules/async/dist/async.js:1158:13
    at /home/manager/service/routes/system-ops.js:62:33
    at handleCallback (/home/manager/service/node_modules/mongodb/lib/utils.js:96:56)

  Code snippet:
        db.collection('node').find({layer: layer}, {_id: 1}).each(function(err, node) {
           
if(err) {
                console
.log("ERROR: node.find()");
           
}


           
if(node == null) {
               
return reply([]);
           
}


           
var nid = ObjectID(node._id).toString();
            db
.collection('ops_log').find({nodeId:nid, ts:{$gte: tsStart, $lte: tsEnd}}).count(function(err, total) {
               
if(err) {
                   
return reply([]);
               
}


                db
.collection('ops_log').find({nodeId: nid, ts:{$gte: tsStart ,$lte: tsEnd}}, {_id: 0, date: 0, nodeId: 0}, function(err, cursor) {
                   
if(err) {
                        console
.log("ERROR: ops_log.find():",err);
                   
}


                    async
.timesSeries(total/ps, function(cnt, next) {
                        cursor
.skip(cnt*ps).limit(ps).each(function(err, item) {
                           
if(err) {
                               
return next(err, cnt);
                           
}


                           
if(item == null) {
                               
next(err, cnt);
                           
}
                       
});
                   
},
                   
function(err, counter) {
                       
if(err) {
                            console
.log("ERROR: in the skip,limit,sort FINAL:",counter, err);
                       
}
                        console
.log("EACH DONE");
                   
});
               
});
           
});
       
});


Mika Saari

unread,
Dec 19, 2016, 7:49:45 AM12/19/16
to node-mongodb-native
Hi,

  I have been wresting this problem much more now, but seems that I can not get around it. If I limit the query to return only 100 documents, I won't get the Cursor not found error anymore, but 100 docs is not enough for one find unfortunately. 

  Could the multiple routers, replicas, config servers cause this kind of problem ?

   I will try coding this same small test application in C and see if it has effect.

   Thanks for any tips,
    -Mika

Christian Kvalheim

unread,
Dec 19, 2016, 8:20:46 AM12/19/16
to node-mong...@googlegroups.com
Are you attempting to load-balance the mongos proxies through some other load-balancer ? Cursors only exist in the context of a mongos instance so if you are load-balancing you will see these issues as the different getMore's goes to other mongos proxies that don't know about the cursor id.

--
You received this message because you are subscribed to the Google Groups "node-mongodb-native" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-mongodb-native+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages