MongoDB

Update a property

1
db.user.update({'login': 'm@magralabs.com'}, {$set: {active: true}});

Authentication

1
db.auth(username, password)

Backup and restore

https://docs.mongodb.org/manual/tutorial/backup-and-restore-tools/

Backup

1
mongodump --collection foobar --db test --out /data/backup/

Restore

1
mongorestore --username guest --password secret --db test /data/backup/foobar.bson

Create index

https://docs.mongodb.org/manual/tutorial/create-a-compound-index/

Set top-level fields

1
2
3
4
db.products.update(
  { _id: 100 },
  { $set: { quantity: 500 } }
)

Query operators

https://docs.mongodb.com/manual/reference/operator/query/

1
db.collection.find( { age: { $eq: 42 } } )

Operators

Sorting

https://docs.mongodb.com/manual/reference/method/cursor.sort/#cursor.sort

1
db.collection.find().sort( { age: 1 } )

Order