Skip to content

Instantly share code, notes, and snippets.

@npentrel
Created September 14, 2018 00:04
Show Gist options
  • Save npentrel/986f66fe54480d4888c818ddfa58bb53 to your computer and use it in GitHub Desktop.
Save npentrel/986f66fe54480d4888c818ddfa58bb53 to your computer and use it in GitHub Desktop.
> 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