installation
Official website Download: https://www.mongodb.org/
Unzip unpack rename to MongoDB move to/usr/local/directory
Create a soft connection
ln-s/usr/local/mongodb/bin/mongod/usr/bin/mongod for mobile server
ln-s/usr/local/mongodb/bin/mongo/usr/bin/mongo for starting the client (shell)
Create directory sudo mkdir-p/data/db is the default startup database path for MongoDB (--dbpath)
Start service $ sudo mongod
Start the client shell $ MONGO
Start HTTP Web UI $ sudo mongod--rest
Basic Concepts
SQL Terminology/Concepts |
MongoDB Terminology/Concepts |
Explanation/Description |
Database |
Database |
Database |
Table |
Collection |
Database Tables/Collections |
Row |
Document |
Data record lines/documents |
Column |
Field |
Data fields/Fields |
Index |
Index |
Index |
Table joins |
|
Table connection, MongoDB not supported |
Primary key |
Primary key |
Primary key, MongoDB automatically sets the _id field as the primary key |
A more intuitive reflection of the correspondence between SQL and MongoDB
Basic syntax
> DB #显示当前所在数据库, default is Test
> use database_name #切换数据库, if the name does not exist, it is equivalent to creating a new database (which is not saved until the collection is created)
> Show dbs/>show databases #查看所有的数据库
> db. collection_name insert ({' xx ': ' oo '}) #创建集合 inserted content formatted as key/value pairs
> db. collection_name Insert (document) #向集合中插入文档 as above
> db. Collection_name.find () #查看已插入的文档
> db.col. (). Pretty () #易读方式查询文档
> db. Dropdatabase () #删除数据库
Ubuntu installation using MongoDB