christkv/node-mongodb-native — Issue #481: findAndModify execute twice callback on error
Author: napa3um
Created: 2012-01-17 15:16:04+00:00
State: open

[napa3um@hive Uni]$ node -v
v0.6.7
[napa3um@hive Uni]$ npm -v
1.1.0-beta-10
[napa3um@hive Uni]$ npm view mongodb version
0.9.8

[napa3um@hive Uni]$ cat test.js

```javascript
var mongo = require('mongodb');
var db = new mongo.Db('uni', new mongo.Server('localhost', 27017, { auto_reconnect: true, native_parser: true }), {});
(new mongo.Collection(db, 'user'))
.findAndModify({_id: new mongo.ObjectID('4f155b9fe3c7896361000002')}, [], { $set: {login: 'admin'} }, {}, function(err, user){
if(err)
console.log('\n---\n', err);
else
console.log('\n---\nok');
});
```
[napa3um@hive Uni]$ node test.js

---
{ [MongoError: E11000 duplicate key error index: uni.user.$login_1 dup key: { : "admin" }]
name: 'MongoError',
lastErrorObject:
{ err: 'E11000 duplicate key error index: uni.user.$login_1 dup key: { : "admin" }',
code: 11001,
n: 0,
connectionId: 89,
ok: 1 },
errmsg: 'E11000 duplicate key error index: uni.user.$login_1 dup key: { : "admin" }',
ok: 0 }

---
{ [MongoError: E11000 duplicate key error index: uni.user.$login_1 dup key: { : "admin" }]
name: 'MongoError',
err: 'E11000 duplicate key error index: uni.user.$login_1 dup key: { : "admin" }',
code: 11001,
n: 0,
connectionId: 89,
ok: 1 }