Introduction to the
MongoDB is a database based on distributed file storage. Written in C++ language. Designed to provide scalable high-performance data storage solutions for WEB applications. MongoDB is a product between relational database and non-relational database. Among non-relational databases, it has the most rich functions and is the most like relational database.
No characteristic
- Not Only SQL
- Key-value pair storage, column storage, document storage, graph database
- Final consistency, not ACID properties
- Unstructured and unpredictable data
- The CAP theorem (!!)
- High performance, high availability and scalability
Directing a concept
1. Comparison of SQL terms
SQL terms/concepts | MongoDB terminology/concepts | Explanation/explanation |
---|---|---|
database | database | The database |
table | collection | Database tables/collections |
row | document | Data record line/document |
column | field | Data fields/fields |
index | index | The index |
table joins | Table joins,MongoDB does not support | |
primary key | primary key | Primary key. MongoDB automatically sets the _ID field as the primary key |
2. Compare SQL conditions
operation | format | sample | Similar statements in an RDBMS |
---|---|---|---|
Is equal to the | {that} | db.col.find({“by”:”ahh”}).pretty() | where by = ‘ahh’ |
Less than | {:{$lt:}} | db.col.find({“likes”:{$lt:50}}).pretty() | where likes < 50 |
Less than or equal to | {:{$lte:}} | db.col.find({“likes”:{$lte:50}}).pretty() | where likes <= 50 |
Is greater than | {:{$gt:}} | db.col.find({“likes”:{$gt:50}}).pretty() | where likes > 50 |
Greater than or equal to | {:{$gte:}} | db.col.find({“likes”:{$gte:50}}).pretty() | where likes >= 50 |
Is not equal to | {:{$ne:}} | db.col.find({“likes”:{$ne:50}}).pretty() | where likes ! = 50 |
Basic statement
- Database operations
- Create a database: use DATABASE_NAME
- To check the database, run show DBS
- DropDatabase: db.dropdatabase ()
- Set operations
- Db.createcollection (COLLECTION_NAME)
- Check out the collection: Show Collections
- Db.collection_name. Drop ()
- The document operation
- Db.collection_name. Insert (document)
- Db.collection_name. Find (query, projection)
- Db.collection_name. Update (document)/db.collection_name. Save (document)
- Db.collection_name. Remove (document)
- other
- Limit (), skip(), sort(), create index: ensureIndex()
- Polymerization db. COLLECTION_NAME. Aggregate (AGGREGATE_OPERATION)
Application scenarios
- Log analysis
- Store user insensitive information and comment information
- The work order system
- Not transactional, read frequently…
note
CAP:
- Consistency (all nodes have the same data at the same time)
- Availability (Ensuring that each request is responded to regardless of success or failure)
- The loss or failure of any information in the system will not affect the continued operation of the system
reference
- www.runoob.com/mongodb/mon…
- Blog.csdn.net/xiaoxiong_w…
- www.cnblogs.com/caihuafeng/…