MONGO database command line common commands

Source: Internet
Author: User

Help #mongodb支持的命令
Show DBS #查看所有数据库
Use test
DB #查看当前连接在哪个数据库
Show Collections #查看所有的collection
Db.help () #当前数据库支持哪些方法
Db.user.help () #当前数据库下的表或者表collection支持的方法

Db.foo.find () #查找所有
Db.foo.findOne () #查找一条记录
Db.foo.find ({' msg ': ' Hello 1 '}). Limit #根据条件检索10条记录

Db.mail_addr.drop () #删除collection
Db.dropdatabase () #删除当前的数据库
Db.foo.remove ({' yy ': 5}) #删除yy =5 records
Db.foo.remove () #删除所有的记录

#存储嵌套的对象
Db.foo.save ({' name ': ' Ysz ', ' address ': {' city ': ' Beijing ', ' Post ': 100096}, ' phone ': [138,139]})

#存储数组对象
Db.user_addr.save ({' Uid ': ' [email protected] ', ' Al ': [' [email protected] ', ' [email protected] ']})

#根据query条件修改, insert if not present, allow multiple records to be modified
Db.foo.update ({' yy ': 5},{' $set ': {' xx ': 2}},upsert=true,multi=true)

MONGO database command line common commands

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.