{
"op": "query",
"ns": "fund_statistic.fund_minute_statistic_collection1588",
"command": {
"find": "fund_minute_statistic_collection1588",
"filter": {
"time": {
"$gte": 1531868400,
"$lt": 1531887084
}
},
"$db": "fund_statistic",
"$readPreference": {
"mode": "primaryPreferred"
},
"lsid": {
"id": UUID(
"f0a2ea9e-f8a4-484f-86cc-d01d04ebea3e"
)
}
},
"cursorid": NumberLong(
"119871802965176"
),
"keysExamined": 101,
"docsExamined": 101,
"numYield": 1,
"locks": {
"Global": {
"acquireCount": {
"r": NumberLong(4)
}
},
"Database": {
"acquireCount": {
"r": NumberLong(2)
}
},
"Collection": {
"acquireCount": {
"r": NumberLong(2)
}
}
},
"nreturned": 101,
"responseLength": 7185,
"protocol": "op_msg",
"millis": 8960,
"planSummary": "IXSCAN { time: 1 }",
"execStats": {
"stage": "FETCH",
"nReturned": 101,
"executionTimeMillisEstimate": 119,
"works": 101,
"advanced": 101,
"needTime": 0,
"needYield": 0,
"saveState": 2,
"restoreState": 1,
"isEOF": 0,
"invalidates": 0,
"docsExamined": 101,
"alreadyHasObj": 0,
"inputStage": {
"stage": "IXSCAN",
"nReturned": 101,
"executionTimeMillisEstimate": 119,
"works": 101,
"advanced": 101,
"needTime": 0,
"needYield": 0,
"saveState": 2,
"restoreState": 1,
"isEOF": 0,
"invalidates": 0,
"keyPattern": {
"time": NumberLong(1)
},
"indexName": "time_1",
"isMultiKey": false,
"multiKeyPaths": {
"time": []
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": 2,
"direction": "forward",
"indexBounds": {
"time": [
"[1531868400, 1531887084)"
]
},
"keysExamined": 101,
"seeks": 1,
"dupsTested": 0,
"dupsDropped": 0,
"seenInvalidated": 0
}
},
"ts": ISODate(
"2018-07-18T04:11:33.487Z"
),
"client": "192.168.10.81",
"allUsers": [],
"user": ""
}
你可能没有对 time 字段做索引。没做索引的话,查询就是线性的。遍历数据库中的条目就很久了。
可以看看 db.collection.getIndexes() 能获取你现在的缓存列表。
如果没有,并且这个业务场景比较常用可以对 time 字段做索引 db.collection.createIndex({time: 1})