A query projection a:true should be equivalent to a:1, however specification of a true value prevents covered index queries apparently due to the following line:
if ( ! e.isNumber() ) _hasNonSimple = true;
Test
c = db.c; c.drop(); c.save( { a:5 } ); assert.eq( { a:5 }, c.find( { a:5 }, { _id:0, a:1 } ).toArray()[ 0 ] ); assert.eq( { a:5 }, c.find( { a:5 }, { _id:0, a:true } ).toArray()[ 0 ] ); c.ensureIndex( { a:1 } ); assert.eq( { a:5 }, c.find( { a:5 }, { _id:0, a:1 } ).toArray()[ 0 ] ); assert( c.find( { a:5 }, { _id:0, a:1 } ).explain().indexOnly ); assert.eq( { a:5 }, c.find( {}, { _id:0, a:true } ).toArray()[ 0 ] ); // Fails because 'true' prevents doing a covered index query. assert( c.find( { a:5 }, { _id:0, a:true } ).explain().indexOnly );
- duplicates
-
SERVER-3156 query projection spec using 'true' instead of '1' prevents covered index query
- Closed