我正在对MongoDB表进行过滤查询,但结果与过滤条件不匹配。
我正在使用以下查询:
db.url_repository.find({"p":0,"pr":0}).limit(10)
但我的结果是
{ "_id" : ObjectId("568742bb60d99e329a115b7a"), "pr" : 0, "p" : 1, "u" : "http://www.blabla", "type" : "regular", "ct" : ISODate("2016-01-02T05:23:39.586Z"), "dt" : ISODate("2016-08-20T14:59:48.759Z") }
{ "_id" : ObjectId("568742bb60d99e329a115b7b"), "pr" : 0, "p" : 1, "u" : "http://www.blabla", "type" : "regular", "ct" : ISODate("2016-01-02T05:23:39.586Z"), "dt" : ISODate("2016-08-20T15:00:00.392Z") }
{ "_id" : ObjectId("568742bb60d99e329a115b7c"), "pr" : 0, "p" : 1, "u" : "http://www.blabla", "type" : "regular", "ct" : ISODate("2016-01-02T05:23:39.586Z"), "dt" : ISODate("2016-08-20T15:00:12.537Z") }
{ "_id" : ObjectId("568742bb60d99e329a115b7d"), "pr" : 0, "p" : 1, "u" : "http://www.blabla/", "type" : "regular", "ct" : ISODate("2016-01-02T05:23:39.587Z"), "dt" : ISODate("2016-08-20T15:00:15.887Z") }
正如您所看到的,它不符合规则,结果包括带有“p”的文档:1
这些结果在MongoDB shell上返回,但pymongo(Python库)也会返回正确的结果。我找不到可能的原因。
非常感谢您的支持。
编辑:explain()结果也在
之下{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "crawlerdb.url_repository",
"indexFilterSet" : false,
"parsedQuery" : {
"$and" : [
{
"p" : {
"$eq" : 0
}
},
{
"pr" : {
"$eq" : 0
}
}
]
},
"winningPlan" : {
"stage" : "LIMIT",
"limitAmount" : 10,
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"pr" : {
"$eq" : 0
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"p" : 1
},
"indexName" : "is_processed",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 1,
"direction" : "forward",
"indexBounds" : {
"p" : [
"[0.0, 0.0]"
]
}
}
}
},
"rejectedPlans" : [
{
"stage" : "LIMIT",
"limitAmount" : 10,
"inputStage" : {
"stage" : "FETCH",
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"p" : 1,
"pr" : -1
},
"indexName" : "url_is_processed_priority",
"isMultiKey" : false,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 1,
"direction" : "forward",
"indexBounds" : {
"p" : [
"[0.0, 0.0]"
],
"pr" : [
"[0.0, 0.0]"
]
}
}
}
}
]
},
"serverInfo" : {
"host" : "barcelona",
"port" : 27017,
"version" : "3.2.7",
"gitVersion" : "4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2"
},
"ok" : 1
}