我的文档结构如下,每个数组元素包含" n"和" v"作为不同类型数据的关键和价值。 (集合名称是doc)
min-height
和索引如下所示。
{
"_id" : 1,
"logs" : [
{ "n" : "facility", "v" : 26 },
{ "n" : "num", "v" : 6 },
{ "n" : "ip", "v" : "137.68.151.104" },
{ "n" : "protocol", "v" : "55902/udp" },
{ "n" : "port", "v" : "53" }
]
},
{
"_id" : 2,
"logs" : [
{ "n" : "facility", "v" : 26 },
{ "n" : "num", "v" : 6 },
{ "n" : "ip", "v" : "137.68.160.51" },
{ "n" : "protocol", "v" : "13438/tcp" },
{ "n" : "port", "v" : "13438" }
]
},
{
"_id" : 3,
"logs" : [
{ "n" : "facility", "v" : 26 },
{ "n" : "num", "v" : 6 },
{ "n" : "ip", "v" : "137.68.160.51" },
{ "n" : "protocol", "v" : "13434/tcp" },
{ "n" : "port", "v" : "53" }
]
},
{
"_id" : 4,
"logs" : [
{ "n" : "facility", "v" : 26 },
{ "n" : "num", "v" : 6 },
{ "n" : "ip", "v" : "137.68.160.184" },
{ "n" : "protocol", "v" : "61662/udp" },
{ "n" : "port", "v" : "53" }
]
},
{
"_id" : 5,
"logs" : [
{ "n" : "facility", "v" : 26 },
{ "n" : "num", "v" : 6 },
{ "n" : "ip", "v" : "137.68.160.51" },
{ "n" : "protocol", "v" : "13435/tcp" },
{ "n" : "port", "v" : "13435" }
]
},
{
"_id" : 6,
"logs" : [
{ "n" : "facility", "v" : 26 },
{ "n" : "num", "v" : 6 },
{ "n" : "ip", "v" : "137.68.160.51" },
{ "n" : "protocol", "v" : "61662/udp" },
{ "n" : "port", "v" : "53" }
]
}
...
我想查询这个条件。 " IP"是" 137.68.160.51"和" port"是" 53"
所以,我这样查询。
>db.doc.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "db_test.doc"
},
{
"v" : 1,
"key" : {
"logs.n" : 1,
"logs.v" : 1
},
"name" : "logs.n_1_logs.v_1",
"ns" : "db_test.doc"
}
]
但是,查询非常慢。 (超过30秒) (" ip" ==" 137.68.160.51"文件计数为10,000,000。结果文件计数无效。)
我认为,MongoDB在使用$和operator的第二次查询时无法使用索引。
如果使用$和运算符进行查询,B查询和C查询, $和:[{A},{B},{C}]。 B和C查询不能使用索引。正确?