Created
January 13, 2015 21:03
-
-
Save vkarpov15/f4067054b3276279ea03 to your computer and use it in GitHub Desktop.
Hanging nextObject() call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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