Created
May 22, 2017 13:01
-
-
Save alcaeus/4509c4479866d51103f03f5d755f5d4f to your computer and use it in GitHub Desktop.
MongoDB findAndModify
This file contains hidden or 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
> db.foo.count() | |
> db.foo.findAndModify({query: { foo: 'bar' }, update: {foo: 'bar'}, upsert: true}) | |
null | |
> db.foo.findAndModify({query: { foo: 'bar' }, update: {foo: 'baz'}, upsert: true}) | |
{ "_id" : ObjectId("5922e0b18c00e100490e9108"), "foo" : "bar" } | |
> db.foo.findAndModify({query: { foo: 'bar' }, update: {foo: 'foobar'}, upsert: true, new: true}) | |
{ "_id" : ObjectId("5922e0b18c00e100490e9108"), "foo" : "foobar" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment