Learn about MongoDB

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.