Answer the question
In order to leave comments, you need to log in
Does Mongo select queries optimize?
Let's say there are two SQL queries
select * from users
and
select username, email from users
As I understand it, they correspond to
> db.users.find();
and
> db.users.find( { }, { username: 1, email: 1 } );
Question: Does Mongo optimize these queries? Does he have a time difference for these requests?
Answer the question
In order to leave comments, you need to log in
Full sample
{
"cursor" : "BasicCursor",
"nscanned" : 1136854,
"nscannedObjects" : 1136854,
"n" : 1136854,
"millis" : 45205,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
}
}
{
"cursor" : "BasicCursor",
"nscanned" : 1136854,
"nscannedObjects" : 1136854,
"n" : 1136854,
"millis" : 40294,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
}
}
you can tritely execute a bunch of such requests and detect the time =) you will visually see the difference, at the same time tell us here.
If you only need 2 fields, then the second option is better, since in the first one you will send the entire collection to the client.
I don’t think that mongo optimizes anything, since there is nothing to optimize here - in both cases, you need to bypass the entire collection, just in the second case, the amount of data sent is less.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question