Skip to content

Instantly share code, notes, and snippets.

@vkarpov15
Created January 13, 2015 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkarpov15/f4067054b3276279ea03 to your computer and use it in GitHub Desktop.
Save vkarpov15/f4067054b3276279ea03 to your computer and use it in GitHub Desktop.
Hanging nextObject() call
// MongoDB 2.6, Linux Mint 17.1, node driver HEAD
/* Output looks like:
```
nextObject returned
Calling nextObject again...
Calling execGetMore
```
The `console.log('second nextObject returned');` line never gets executed and the program exits because of no listeners
*/
var mongodb = require('mongodb');
mongodb.MongoClient.connect('mongodb://localhost:27017', function(error, db) {
if (error) {
throw error;
}
db.collection('test').insert({ x: 1 }, function(error) {
if (error) {
throw error;
}
db.collection('test').insert({ x: 2 }, function(error) {
if (error) {
throw error;
}
db.collection('test').find({}, {batchSize: 2}, function(error, cursor) {
if (error) {
throw error;
}
cursor.nextObject(function(error, obj) {
if (error) {
throw error;
}
db.close();
cursor.nextObject(function(error, obj) {
console.log('nextObject returned');
if (error) {
throw error;
}
console.log('Calling nextObject again...');
cursor.nextObject(function(error, obj) {
console.log('second nextObject returned');
if (error) {
throw error;
}
});
});
});
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment