0
我收藏〜2000000個文件。 字段unit
具有指數:{"unit" : 1.0}
爲什麼MongoDB計算這麼久?
查詢:
db.getCollection('CollectionName').find({"unit":"value"}).count()
進行5秒(導致200個000文檔)
查詢:
db.getCollection('CollectionName').find({"unit":"value"})
執行0.005秒
爲什麼?
db.collection.count相當於db.collection.find –
它是*功能*等同,但*不*函是不同的。 find(...)。count()會讀取所有200,000個文檔,然後對它們進行計數,而count(...)將執行計數服務器端並只返回與給定過濾器相匹配的文檔數。 – glytching
db.getCollection('CollectionName')。count({「unit」:「value」})dothe't help,query perform 5 sec –