Reputation: 3157
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.
Upvotes: 3
Views: 220
Reputation: 2397
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.
Upvotes: 2