Last active
August 29, 2015 14:00
-
-
Save kjirou/95abfcade86c1474392b to your computer and use it in GitHub Desktop.
存在した _id が設定済みの doc を save() するとエラー
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 sandbox = new Sandbox({ | |
_id: ObjectId('既存の_id'), | |
}); | |
sandbox.someProp = 'New value'; | |
sandbox.save(function(err, sandbox){ | |
console.log(err); | |
}); | |
// | |
// -> [MongoError: E11000 duplicate key error index: tomcom.sandboxes.$_id_ dup key: { : ObjectId('既存の_id') }] | |
// | |
// これはエラーにならない | |
Sandbox.findById(ObjectId('既存の_id'), function(err, sandbox){ | |
sandbox.rootName = 'New value'; | |
sandbox.save(function(err, sandbox_){ | |
console.log(sandbox_); | |
}); | |
}); | |
// new Doc({_id:ObjectId('既存の_id')}) と findById したものは違う |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment