mongo的常用命令

1 登录命令
$/apps/product/mongodb/bin/mongo  127.0.0.1:27006/test  -u test -p test
MongoDB shell version: 3.0.3
connecting to:127.0.0.1:27006/test
Server has startup warnings:
2018-09-25T19:17:59.643+0800 I CONTROL  [initandlisten]
mongotest:PRIMARY>

2 help命令
mongotest:PRIMARY> help
    db.help()                    help on db methods
    db.mycoll.help()             help on collection methods
    sh.help()                    sharding helpers
    rs.help()                    replica set helpers
    help admin                   administrative help
    help connect                 connecting to a db help
    help keys                    key shortcuts
    help misc                    misc things to know
    help mr                      mapreduce

    show dbs                     show database names
    show collections             show collections in current database
    show users                   show users in current database
    show profile                 show most recent system.profile entries with time >= 1ms
    show logs                    show the accessible logger names
    show log [name]              prints out the last segment of log in memory, 'global' is default
    use <db_name>                set current database
    db.foo.find()                list objects in collection foo
    db.foo.find( { a : 1 } )     list objects in foo where a == 1
    it                           result of the last line evaluated; use to further iterate
    DBQuery.shellBatchSize = x   set default number of items to display on shell
    exit                         quit the mongo shell
3 查询相关命令

mongo中有数据库,但是数据库里不是表,而是集合,换了个名称。开始不知道,还一脸懵逼,看了help命令才知道。

show dbs                     show database names(显示所有数据库)
show collections             show collections in current database(显示当前数据下的集合(类似于mysql show tables;))
db.foo.find()                list objects in collection foo(查询当前数据库下foo集合中的所有记录,类似于 mysql中 select * from foo;)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容