简体   繁体   中英

Slow distinct() MongoDB query on hashed index collection field

I've got a collection 55 million rows in it, and I want to be able to do db.collection.distinct(foo) , but that's slow. In this case, there's only a single value for "foo" through the entire collection, so I'd expect it to be fast.

I've added an index (foo: "hashed") , but it's still ~30 seconds, even though there's a single value

Do I have to use a non-hashed index to get decent speed on this, or am I missing some other aspect?

Edit: I've also tried a b-tree index which doesn't improve speed at all that I can tell. { "values" : [ "foo" ], "stats" : { "n" : 55316753, "nscanned" : 55316753, "nscannedObjects" : 0, "timems" : 14783, "cursor" : "BtreeCursor baz_1" }, "ok" : 1 }

通过升级到MongoDB 3.0(以前我在其中运行2.4.9)已解决了该问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM