Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-6854

query projection spec using 'true' instead of '1' prevents covered index query

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.8.1
    • Component/s: Querying, Usability
    • ALL

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

            Assignee:
            Unassigned Unassigned
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: