Created
April 19, 2012 19:16
-
-
Save manishtpatel/2423295 to your computer and use it in GitHub Desktop.
findandmodify issue
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
var mongodb = require('mongodb'), | |
request = true; | |
var db = new mongodb.Db('test_db', new mongodb.Server("127.0.0.1", 27017, { | |
auto_reconnect: true | |
}), {}); | |
// listen on error | |
db.on("error", function(err) { | |
console.log('open request ', request); | |
console.error('db on error'); | |
console.dir(err); | |
}); | |
// open connection | |
db.open(function(err, client) { | |
if (err) { | |
console.error(err); | |
} | |
var collection = new mongodb.Collection(client, 'test_collection'); | |
// define find and modify | |
var findAndModifyLoop = function() { | |
// mark request = true as sending mongo request | |
request = true; | |
console.log('findAndModify request (should not be last)'); | |
collection.findAndModify({ | |
hello: 'world' | |
}, // query | |
[ | |
['_id', 'asc'] | |
], // sort order | |
{ | |
$set: { | |
hi: 'there' | |
} | |
}, // replacement, replaces only the field "hi" | |
{}, // options | |
function(err, object) { | |
if (err) { | |
console.warn('findAndModify response ', err.message); // returns error if no matching object found | |
} else { | |
console.log('findAndModify response', object); | |
} | |
// no more out standing request | |
request = false; | |
// on result does it again | |
findAndModifyLoop(); | |
}); | |
}; | |
// start the loop | |
findAndModifyLoop(); | |
}); | |
// db.on("close", function(err) { | |
// console.log('open request ', request); | |
// console.error('db on close'); | |
// console.dir(err); | |
// }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run this js file
While running issue 'net stop mongodb'
I am seeing two results, either case i consider error case
1> It throws an error
2> Its quiting without findAndModify calling callback
OS: windows 7 ultimate, sp1, x64
Mongodb: v 2.0.4, windows x64 version, running as service