在具有服务器记录的MongoDB集合中将服务器状态设置为非活动状态?
让我们创建一个包含文档的集合-
> db.demo707.insertOne(
... {
... id:101,
... "serverInformation":
... [
... {
... "IP":"192.56.34.3",
... "Status":"Active"
... },
... {
... "IP":"192.56.36.4",
... "Status":"Inactive"
... }
... ]
... }
... );
{
"acknowledged" : true,
"insertedId" : ObjectId("5ea6f852551299a9f98c93c8")
}在find()方法的帮助下显示集合中的所有文档-
> db.demo707.find();
这将产生以下输出-
{ "_id" : ObjectId("5ea6f852551299a9f98c93c8"), "id" : 101, "serverInformation" : [ { "IP" : "192.56.34.3", "Status" : "Active" }, { "IP" : "192.56.36.4", "Status" : "Inactive" } ] }以下是将活动服务器设置为非活动状态的查询-
>db.demo707.update({"serverInformation.IP":"192.56.34.3"},{$set:{"serverInformation.$.Status":"Inactive"}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })在find()方法的帮助下显示集合中的所有文档-
> db.demo707.find();
这将产生以下输出-
{ "_id" : ObjectId("5ea6f852551299a9f98c93c8"), "id" : 101, "serverInformation" : [ { "IP" : "192.56.34.3", "Status" : "Inactive" }, { "IP" : "192.56.36.4", "Status" : "Inactive" } ] }热门推荐
10 书写大赛祝福语范文简短
11 女生新年漂亮祝福语简短
12 66红包祝福语简短的
13 对战友的祝福语简短
14 简短的古风生日祝福语
15 喝酒祝福语大全简短新颖
16 公司生日祝福语员工简短
17 带猫的祝福语简短
18 朋友升迁的祝福语简短