Skip to content

Instantly share code, notes, and snippets.

@npentrel
Last active September 13, 2018 23:59
Show Gist options
  • Save npentrel/01e42b7e6c7273c15bf5878d4dd70335 to your computer and use it in GitHub Desktop.
Save npentrel/01e42b7e6c7273c15bf5878d4dd70335 to your computer and use it in GitHub Desktop.
> db.alphabet.insert({
"_id": "11111",
"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": "11111" },
{
$push: {
array: {
$each: ['i'],
$position: 8
}
}
}
)
// Check the results:
> db.alphabet.find({ "_id": "11111" })
{ 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