[英]Regex query MongoDB Performance issue
我有Mongodb集合,其中包含單個字段,每天我收到31000個文檔,在集合中,我有將近6個月的數據
這是我的數據在數據庫中的樣子
{
"_id" : ObjectId("59202aa3f32dfba00d0773c3"),
"Data" : "20-05-2017 18:38:13 SYSTEM_000_00_SAVING ",
"__v" : 0
}
{
"_id" : ObjectId("59202aa3f32dfba00d0773c4"),
"Data" : "20-05-2017 18:38:13 SyTime_000_09_00:00 ",
"__v" : 0
}
這是我的查詢代碼
DBObject query = new BasicDBObject();
Pattern regex = Pattern.compile("20-05-2017");
query.put("Data", regex);
我已經創建了索引,但是它仍然很慢
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "NOB_SRB.fdevices"
},
{
"v" : 1,
"unique" : true,
"key" : {
"Data" : 1.0
},
"name" : "Data_1",
"ns" : "NOB_SRB.fdevices"
}
]
將輸入錨^
的開頭添加到正則表達式的開頭:
Pattern regex = Pattern.compile("^20-05-2017");
因為你的正則表達式沒有錨,整個場中搜索在它去任何地方 ,這需要在該領域的每一個字符進行比較。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.