I keep seeing the projection parameter in find() queries and was wondering if adding it makes things faster. I assume it does for large documents, but what about small documents of, say, 10 values or so?
I am seeking to optimize a project where MANY MANY small queries are performed.
You should profile. In MongoDB shell, try db.collection.find().explain().
If you have indexes, then it may help. Indexed queries are faster and if your queries only use fields stored in the index itself, you'll have a covered query (indexOnly in cursor.explain()). The projection parameter help to turn a query into a covered query.
If you insert documents more frequently than you read documents, then it might not be a good idea to use indexes, but you should always profile it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With