4
我有MongoDB的集合包含單場,每一天我收到31000頁的文件和集合中,我有近6個月的數據正則表達式查詢MongoDB的性能問題
這裏是我的數據看起來像在數據庫
{
"_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"
}
]
這是一個很好的答案,一個小基準:https://stackoverflow.com/questions/17942275/speed-up-regex-string-search-in-mongodb –