mongodb 命令速查

mongodb 手册。

连接

1
mongo 192.168.1.200:27017/test -u user -p password

db

1
2
3
4
5
# 查看 db
show dbs;

# 使用 db
use <db_name>;

collection

1
2
# 查看 collections
show collections;

常用命令

1
2
3
4
5
6
7
8
# 创建唯一索引
db.collection_name.ensureIndex({"key_name":1},{"unique":true})

# 复合唯一索引
db.collection_name.ensureIndex({'key1':1, 'key1':1})

# 删除文档
db.getCollection('domain').remove({"provison_state": "success", "industry": null})