1. 程式人生 > >mongodb 查詢,更新操作

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)