I need just one property of one document.
I see that I can’t .project
after .findOne
, only after .find
.
I’m concerned about the data egress (although it is small) and the performance of the request.
With my understanding of how MongoDB queries a collection - once it finds a satisfying record in findOne
it immediately returns. But using find,
it needs to search through the whole collection - right?
If it matters, I am searching on _id (a single _id), so since I’m searching on an index, how would it affect the performance to use find
(and then I can use project) vs findOne
.
On the other hand, the size of the full document which would be returned from the findOne
query is very small.
So I’m just not sure which is best. Thanks for any help.
Edit to add: Digging around, I found the findOptions and set the limit to 1 (and went ahead and just used the project in the findOptions). I think this will work well for me.