If you think MongoDB is comparable with SQL, you don't know database. π
Here's what all the basics you need to know about MongoDB:
Here's what all the basics you need to know about MongoDB:
MongoDB is a DBMS (database management system). π
A DMBS is often used for carefully organized data, for retrieval by the web server. (e.g. web user, shop inventory, message board).
A DMBS is often used for carefully organized data, for retrieval by the web server. (e.g. web user, shop inventory, message board).
There are two mainly types of DMBS: relational database and non-relational database. π½
Relational database means tables of rows and columns.
Non-relational (NoSQL) database means flexible documents, without a fixed table structure. ποΈ
Relational database means tables of rows and columns.
Non-relational (NoSQL) database means flexible documents, without a fixed table structure. ποΈ
MDB is an open-source NoSQL database management system (DBMS).
It is:
- Non-relational (lack of support of the concept of relations)
- Not easy to implement joins in query
- Supporting dynamic schema
MongoDB stores data records as 'documents' π
It is:
- Non-relational (lack of support of the concept of relations)
- Not easy to implement joins in query
- Supporting dynamic schema
MongoDB stores data records as 'documents' π
What is a 'document' in MongoDB? π€
Document is similar to JS object, or a row in a relational DB.
A MongoDB document is a JSON-style data structure composed of field-and-value pairs.
They are stored as 'BSON' (Binary JSON): a binary-encoded serialization of JSON documents. π€
Document is similar to JS object, or a row in a relational DB.
A MongoDB document is a JSON-style data structure composed of field-and-value pairs.
They are stored as 'BSON' (Binary JSON): a binary-encoded serialization of JSON documents. π€
What is 'BSON'? π€
BSON is a binary-encoded serialization of JSON documents.
The value of a field can be any of the BSON types (String, Double,
32/64-bit integer, etc.), including other documents, arrays, and arrays of documents! β¨
See more detail on: mongodb.com
BSON is a binary-encoded serialization of JSON documents.
The value of a field can be any of the BSON types (String, Double,
32/64-bit integer, etc.), including other documents, arrays, and arrays of documents! β¨
See more detail on: mongodb.com
How are document stored? π₯
By default, MDB automatically assigns a unique value of type 'ObjectId' in a compulsory 'field _id'.
'_id' serves as the primary key, it:
- is always the first field in the document
- value must be unique
- can be a value of any type except array β¨
By default, MDB automatically assigns a unique value of type 'ObjectId' in a compulsory 'field _id'.
'_id' serves as the primary key, it:
- is always the first field in the document
- value must be unique
- can be a value of any type except array β¨
Using MongoDB with Node.js β¨
In a web application, the backend (e.g. Node.js) is responsible to access the database server.
Two possible ways to access MongoDB from Node.js:
- Use MDB directly with Mongo Shell commands in
Node.js
- Use Mongoose π¦
In a web application, the backend (e.g. Node.js) is responsible to access the database server.
Two possible ways to access MongoDB from Node.js:
- Use MDB directly with Mongo Shell commands in
Node.js
- Use Mongoose π¦
What is Mongoose? π€
It's an Object Data Modeling (ODM) library on top of MongoDB.
It supports schemas to describe documents:
- type check and conversion
- check if a value is unique
- check if a required value is omitted
It simplifies interaction between MDB and Node.js β¨
It's an Object Data Modeling (ODM) library on top of MongoDB.
It supports schemas to describe documents:
- type check and conversion
- check if a value is unique
- check if a required value is omitted
It simplifies interaction between MDB and Node.js β¨
How to CRUD in MongoDB?
CRUD are the common operations for data items:
βοΈ Create
π Read / Retrieve
π Update
π― Delete
CRUD operations are supported by Mongoose query functions.
Queries are executed asynchronously, and results are passed to callbacks π€
CRUD are the common operations for data items:
βοΈ Create
π Read / Retrieve
π Update
π― Delete
CRUD operations are supported by Mongoose query functions.
Queries are executed asynchronously, and results are passed to callbacks π€
Note: This thread is inspired by my previous controversial tweet - feel free to check the comments for explanations of why they're incomparable! π
That's a wrap!
If you enjoyed this thread:
1. Follow me @emiko_dev for more of these
2. RT the tweet below to share this thread with your audience
If you enjoyed this thread:
1. Follow me @emiko_dev for more of these
2. RT the tweet below to share this thread with your audience
Loading suggestions...