MongoDB 'count()' is very slow. How do we refine/work around with it?

前端 未结 4 435
再見小時候
再見小時候 2020-11-30 04:19

I am currently using MongoDB with millions of data records. I discovered one thing that\'s pretty annoying.

When I use \'count()\' function with a small number of qu

4条回答
  •  Happy的楠姐
    2020-11-30 05:13

    You are pretty much out of luck for now, count in mongodb is awful and won't be getting better in the near future. See: https://jira.mongodb.org/browse/SERVER-1752

    From experience, you should pretty much never use it unless it's a one time thing, something that occurs very rarely, or your database is pretty small.

    As @Andrew Orsich stated, use counters whenever possible (the downfall to counters is the global write lock, but better than count() regardless).

提交回复
热议问题