Created
September 14, 2018 00:10
-
-
Save npentrel/206b68bfefc44899afdd29d479ba0ad3 to your computer and use it in GitHub Desktop.
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.alphabet.insert({ | |
| "_id": "66666", | |
| "array": ['b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'] | |
| }) | |
| // We missed the 'a'! | |
| // Let's add it to the beginning by specifying $position: -0. | |
| > db.alphabet.update( | |
| { "_id": "66666" }, | |
| { | |
| $push: { | |
| array: { | |
| $each: ['a'], | |
| $position: -0 | |
| } | |
| } | |
| } | |
| ) | |
| // Check the results: | |
| > db.alphabet.find({ "_id": "66666" }) | |
| { "array" : [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" ] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment