带有项目背景的MongoDB常用命令操作演示。

数据库相关

1
show dbs;
1
use hohistar-iot

集合相关

1
show collections;

指定条件查询文档

1
db.tbl_data_center.find({appKey:"7657f774479207xxxxc2dacb4d625326af3xxxxx", env: "UAT"});

更新文档:

1
db.tbl_data_center.update({appKey:"7657f774479207c2dxxxxacb4d625326af3xxxxx", env: "UAT"}, {bizServer: "uat-1.hohistar.com.cn"})

注意:这个方法会更新整个文档,而不是文档中的某个或某几个字段

要更新某一个属性,需要用 “$set”