mongodb 查询,更新操作

mongodb的项:


{ "_id" : ObjectId("5bea9acf484c0d3bed60eddc"), "filter_type" : "ip", "effective_time" : 1, "day_month" : 0, "content" : "both    10.10.10.10 ", "description" : "测试10.10.10.10的过滤" }

我们要在mongodb中查找包含content包含10.10.10.10的项。

可以使用如下语句:
1.

db.collection.find({"content":/.regex./})
db.collection.find({"username" : {$regex : ".regex.*"}});

具体查找语句如下:
1

db.test.find({"content":/.*172\.24\.100\.1./})

2

db.test.find({"content":{$regex:".*172\.24\.100\.1."}})

更新操作
1.删除字段
{“day_month”:{“KaTeX parse error: Expected 'EOF', got '}' at position 9: gte" : 0}̲}:update第一个参数类似…unset:{“day_month”:”"}}:这是需要删除的字段名字

db.test.update({"day_month":{"$gte" : 0}}, {$unset:{"day_month":""}}, false, true)

猜你喜欢

转载自blog.csdn.net/yrx0619/article/details/84071220