Skip to content

Instantly share code, notes, and snippets.

@npentrel
Created September 14, 2018 00:07
Show Gist options
  • Save npentrel/19312d7d520e03b4dc24f14e41931bf3 to your computer and use it in GitHub Desktop.
Save npentrel/19312d7d520e03b4dc24f14e41931bf3 to your computer and use it in GitHub Desktop.
> db.tracking.insert({
"_id": "44444",
"recentItems": ['Apples', 'Bananas', 'Cherries']
})
> db.tracking.update(
{ "_id": "44444" },
{
$push: {
"recentItems": {
$each: ['Dates'],
$slice: -3,
}
}
}
)
// Check the results:
> db.tracking.find({ "_id": "44444" })
{ "recentItems" : [ "Bananas", "Cherries", "Dates" ] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment