1. 程式人生 > >mongodb子集合的模糊查詢

mongodb子集合的模糊查詢

庫名:hongyan_imlog; 

集合名:chat_201802_1;

資料:{ "_id" : ObjectId("5a977aa97f8b9a0684b2ff85"), "content" : { "content" : "沒有" }, "dateTime" : NumberLong(1519574651) }


需要對content裡面的content做正則匹配或模糊查詢:
show dbs;
use hongyan_imlog;
show collections; 
db.chat_201802_1.find({"content.content":/沒有/i});
db.chat_201802_1.find({
content:{
   content:"沒有"
}
});  // 這種形式不能正則,只能相等查詢


//效能測試
db.chat_201802_1.find({"classname":"RC:TxtMsg","content.content":/沒有/i}).sort({dateTime:1}).skip(1000).limit(100).explain("executionStats")