Hello there,
I’m trying to optimize my MongoDB collection for queries made from a service using the findOne
method. Specifically, I need to query based on both the userId
and userAccessCode
fields, where each user can have up to 32 associated codes. The userId
and userAccessCode
properties are both saved as strings in the database. So each user can have upto 32 documents.
To improve query performance, I’ve created an index on these fields using the following code: db.collection.createIndex({ userId: 1, userAccessCode: 1 })
. However, I haven’t noticed any performance improvements yet, and I’m wondering if there is a better type of index to use or if I’ve done everything correctly so far.
Here’s an example of what a document in my collection might look like:
{
userId: "someid" // string,
userAccessCode: "adcdsdfdf" // string,
date: 'currentDate',
// Other fields...
}
Thanks in advance