Hi all
will findOne({_id: ObjectId(id), userId: userName}) be using default _id index?
Thanks
Vladimir
Hello @Vladimir_Vorobiev1, welcome to the forum!
You can know about how and what index is being used with your query by generating a Query Plan on a query. Use the explain
method for that. But, not all collection methods support the explain
, and findOne
is one that doesn’t allow it. So, as an alternative you can generate the query plan by using the find
method for your query.
Useful resources:
- A forum post: Explain function exception with findOne
- MongoDB Manual: db.collection.explain
1 Like