Skip to content

Instantly share code, notes, and snippets.

@npentrel
Created September 14, 2018 00:03
Show Gist options
  • Save npentrel/6f130c7ed66b5ffac50fcec66fa2a1c3 to your computer and use it in GitHub Desktop.
Save npentrel/6f130c7ed66b5ffac50fcec66fa2a1c3 to your computer and use it in GitHub Desktop.
> db.alphabet.insert({
"_id": "22222",
"array": ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j']
})
// We missed the 'i'!
// Let's add it in the position before the last element.
> db.alphabet.update(
{ "_id": "22222" },
{
$push: {
array: {
$each: ['i'],
$position: -1
}
}
})
// Check the results:
> db.alphabet.find({ "_id": "22222" })
{ "array" : [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" ] }v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment