Relative Content

Tag Archive for javascriptnode.jsdatabasemongodb

Is there a way to make this query more optimal?

I have two MongoDB collections Contact and ContactGroup. In a contact document there’s a field called groups which stores the Object IDs of a contact group (ContactGroup) in an array to easily allow querying for all contacts that belong to a specific contact group. Now the issue is with a small amount of documents in the database this modelling worked fine but as the database has scaled to over 800k documents to run a query to count all contacts that belong to a contact group is very slow which is roughly about 16-25s. What is a more optimal way to go about this?