MongoDB Basics
Atlas
-
Replica Set - a few connected machines that store the same data to ensure that if something happens to one of the machines the data will remain intact. Comes from the word replicate - to copy something.
-
Instance - a single machine locally or in the cloud, running a certain software, in our case it is the MongoDB database.
-
Cluster - group of servers that store your data.
BSON
BSON (Binary JSON) Serialization
Import & Export
SRV connection string - a specific format used to establish a connection between your application and a MongoDB instance
# JSON
mongoimport --uri="mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/sample_supplies" --drop sales.json
mongoexport --uri="mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/sample_supplies" --collection=sales --out=sales.json
# BSON
mongorestore --uri "mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/sample_supplies" --drop dump
mongodump --uri "mongodb+srv://<your username>:<your password>@<your cluster>.mongodb.net/sample_supplies"
mongo Shell
cursor
: A pointer to a result set of a querypointer
: A direct address of the memory location
CRUD
Create
insert()
Delete
deleteOne()
deleteMany()
drop()
Update
Update Operators — MongoDB Manual
updateOne()
updateMany()
Read
find()
db.<collection_name>.find({field: "value"}).count()
db.<collection_name>.find({field1: "value1", field2: "value2"})
db.<collection_name>.find({field1: "value1", field2: "value2"}).pretty()