Enter Mongodb:mongo
Exit Mongodb:exit
Show All libraries: Show DBS
Switch database: Use database name
View your library: DB
Delete Library: Db.dropdatabase ()
View a collection of current databases: Show collections
Collection creation: db.createcollection (name, options) collection name must be quoted
Delete collection: Db. Collection name. Drop ()
Insert data: DB. Collection name. Insert (document) #插入文档时, if you do not specify the _id parameter, MongoDB assigns the document a unique Objectid
Insert single: DB. Collection name. Insert ({name: ' Zhang San ', age:18})
Insert multiple: DB. collection name. Insert ([{name: ' Harry ', Sex: ' Male ', age:18}, {name: ' Zhang San ', Sex: ' Female ', age:30}, {name: ' John Doe ', Sex: ' Male ', age : 48}])
Query data: DB. Collection name. Find () #查询所有
Beauty query: Db. Collection name. Find (). Pretty ()
Update data: DB. Collection name. Update (condition),<update>) #单条更新
Multiple updates: DB. Collection name. Update ((condition), <update>, {multi:true})
Specifies the property update, through the operator $set:db. Collection name. Update (condition), {$set: <update>})
Delete data: Db. Collection name. Remove (condition) #默认删除所有
Delete Single: DB. Collection name. Remove ((condition), {justone:true})
Python Operation MongoDB
Install Python package: Pip install Pymongo
Introducing Package Pymongo:import Pymongo
Establish the connection and create the client: client= Pymongo. Mongoclient (host name, port) #本机 (' 127.0.0.1 ', 27017)
Specify database: db=client[database name]
Specified collection: col=db [collection name]
Common methods:
Learn about MongoDB