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

XMLWordPrintableJSON

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

      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
              Reporter:
              Aaron Staple (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: