If we have a collection photos and each entry is a large document which contains all the information about photo including views details and detailed upvotes/downvotes.
{
_id:ObjectId('...'),
title:'...',
location:'...',
views:[
{...},
{...},
...
],
upvotes:[
{...},
{...},
...
],
downvotes:[
{...},
{...},
...
],
}
Which query would work faster and be more effective (memory, CPU usage):
db.photos.find().limit(100)
OR
db.photos.find({}, {views:0,upvotes:0,downvotes:0}).limit(100)
?
you could it do yourself. just add
explain()at the end of query.for example:
mills param is what you want
If you want to see cpu usage just add
--cpukey in launchmongodscript.http://docs.mongodb.org/manual/reference/explain/
You could provide
hint()to mongo forprojection()smth like this:we have simple collection:
Which consist of 23 elements:
Now we can create compound index:
And provide mongo a hint to use index for projection.