-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.2.2
-
Component/s: None
-
Environment:OSX, Node 6.9.1
-
Empty show more show less
When a collection.find().limit() is called with APM being activated, the cursor for the find() call does not get killed. The key is to use the limit() function with a number that is less than the total number of records in the collection.
Here is a full repro:
var mongodb = require("mongodb"); var url = 'mongodb://localhost:27017' var instrumenter = mongodb.instrument(); var db; var adminDb; var cursor; var cursorCountBefore; var cursorCountAfter; mongodb.MongoClient.connect(url) .then(connection => { db = connection; admindb = db.admin(); collection = db.collection('MyCollection'); // make sure collection has records (more than 2) return collection.insertMany([ {a : 1}, {a : 2}, {a : 3} ]); }) .then(() => { // get number of cursors before return admindb.serverStatus(); }) .then(result => { cursorCountBefore = result.cursors.clientCursors_size; cursor = collection.find({}).limit(2); // the issue is not there without the limit call // cursor = collection.find({}) return cursor.toArray(); }) .then(arr => { return cursor.close(); }) .then(() => { // get number of cursors after return admindb.serverStatus(); }) .then(result => { cursorCountAfter = result.cursors.clientCursors_size; console.log(cursorCountBefore); console.log(cursorCountAfter); }) .catch(err => { console.log('error: ' + err); })