Created
September 14, 2018 00:04
-
-
Save npentrel/986f66fe54480d4888c818ddfa58bb53 to your computer and use it in GitHub Desktop.
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
> db.alphabet.insert({ | |
"_id": "33333", | |
"array": ['a', 'b', 'c', 'd', 'e', 'i', 'j'] | |
}) | |
// We missed the 'f', the 'g', and the 'h'! | |
// Let's add them in the position before the last two elements. | |
> db.alphabet.update( | |
{ "_id": "33333" }, | |
{ | |
$push: { | |
array: { | |
$each: ['f', 'g', 'h'], | |
$position: -2 | |
} | |
} | |
} | |
) | |
// Check the results: | |
> db.alphabet.find({ "_id": "33333" }) | |
{ "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