Skip to content

Instantly share code, notes, and snippets.

@awssimplified
Last active April 25, 2022 15:22
Show Gist options
  • Save awssimplified/75ca785b87f4115ada2257576374a3ea to your computer and use it in GitHub Desktop.
Save awssimplified/75ca785b87f4115ada2257576374a3ea to your computer and use it in GitHub Desktop.
1. SHOW ALL DATABASES
show dbs
2. SHOW CURRENT DATABASE
db
3. CREATE DATABASE
use transactions
4. CREATE COLLECTION / TABLE
db.createCollection('transactions')
5. SEE ALL ITESM
db.transactions.find()
6. CREATE RECORD
db.transactions.insert({
id: 1,
type: 'PURCHASE',
amount: 50,
ids: ["001", "002"],
customer: {
name: "John Doe",
address: "123 Fake St"
},
premiumCustomer: true
})
# Mention ^ has inert many
7. GET ALL ROWS
db.transations.find({ amount: 50 })
8. UPDATE - Blow everything away
db.transactions.update({ id: 1 },
{
id: 1,
amount: 49
}
)
9. UPDATE SPECIFIC FIELD
db.transactions.update({ id: 1},
{
$set: { "type": "REFUND" }
},
{
upsert: true
})
10. DELETE ROW
db.posts.remove({id: 1})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment