Skip to content

Instantly share code, notes, and snippets.

@npentrel
Last active August 3, 2018 21:14
Show Gist options
  • Save npentrel/41ca383e43967038a9622e38b2eebd59 to your computer and use it in GitHub Desktop.
Save npentrel/41ca383e43967038a9622e38b2eebd59 to your computer and use it in GitHub Desktop.
Use aggregation expressions in queries with $expr - Insert operation
> db.accounts.insertMany([
   {"_id": 1, "credits": 5000, "expenses": [2000, 2000]},
   {"_id": 2, "credits": 4000, "expenses": [1000, 4000, 2000]},
   {"_id": 3, "credits": 3000, "expenses": [1500, 750]},
   {"_id": 4, "credits": 2000, "expenses": [2500, 750]}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment