Skip to content

Instantly share code, notes, and snippets.

@guarmo
Last active January 11, 2021 07:11
Show Gist options
  • Save guarmo/ddc05ff4224d8d14df2bd69cbb46ac0c to your computer and use it in GitHub Desktop.
Save guarmo/ddc05ff4224d8d14df2bd69cbb46ac0c to your computer and use it in GitHub Desktop.

Start

mongo

Available commands

help

Available collections

show collections

See current database

db

See all available databases

show databases

Create and use new database

use databasename

Create

Insert data

db.’collectionname’.insert({‘JS object here})

Preview collection

db.’collectionname’.find()

Finds elements with certain key-value property

db.’collectionname’.find({ ‘key’: ‘value’})

Update one element

db.’collectioname’.upadateOne({‘key’: ‘value’}, {$set: {‘key’: ‘value’, ‘key1’: ‘value1’}} 

Update many elements

db.’collectionname’.updateMany({‘key’:’value’}, {$set: {‘key: ‘value’, ‘key’: ‘value’}})

Delete one element

db.’collectionname’.deleteOne({‘key’: ‘value’})

Delete many elements

db.’collectionname’.deleteMany({‘key: ‘value’})

Delete entire collection

db.’collectionname’.deleteMany({})
$gt - greater 
$gte - greater or equal
$lt - less than
$lte - less than or equal
$and
$not
$nor 
$or
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment