[SERVER-6854] query projection spec using 'true' instead of '1' prevents covered index query Created: 25/Aug/12  Updated: 15/Feb/13  Resolved: 25/Aug/12

Status: Closed
Project: Core Server
Component/s: Querying, Usability
Affects Version/s: 1.8.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: indexing
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-3156 query projection spec using 'true' in... Closed
Operating System: ALL
Participants:

 Description   

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 );


Generated at Thu Feb 08 03:12:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.