Search code examples
mongodbdatabase-performance

Is it possible to run queries on 200GB data on mongodb with 16GB RAM?


I am trying to run a simple query to find number of all records with a particular value using:

db.ColName.find({id_c:1201}).count()

I have 200GB of data. When I run this query, mongodb takes up all the RAM and my system starts lagging. After an hour of futile waiting, I give up without getting any results.

What can be the issue here and how can I solve it?


Solution

  • I believe the right approach in the NoSQL world isn't trying to perform a full query like that, but accumulate stats overtime.

    For example, you should have a collection stats with arbitrary objects which should own a kind or id property that can take a value like "totalUserCount". Whenever you add an user, you also update this count.

    This way you'll get instant results. It's just getting a property value in a small collection of stats.

    BTW, this slowness should be originated by querying objects by a non-indexed property in your collection. Try to index id_c and probably you'll get quicker results.