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

Count with hint doesn't work when hint is a document

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.6, 2.7.7
    • Affects Version/s: 2.6.3, 2.7.4
    • Component/s: Querying
    • Labels:
      None
    • ALL
    • Hide
      t = db.jstests_count_hint;
      t.drop();
      
      t.save( { i: 1 } );
      t.save( { i: 2 } );
      assert.eq( 2, t.find().count() );
      
      // create a sparse index which should have no entries
      t.ensureIndex( { x:1 }, { sparse:true } );
      
      assert.eq( 0, t.find( { i: 1 } ).hint( "x_1" ).count(), "A" );
      assert.eq( 0, t.find( { i: 1 } ).hint( {x: 1} ).length(), "B" ); // With just find works
      assert.eq( 0, t.find( { i: 1 } ).hint( {x: 1} ).count(), "C" ); // Fails
      
      Show
      t = db.jstests_count_hint; t.drop(); t.save( { i: 1 } ); t.save( { i: 2 } ); assert.eq( 2, t.find().count() ); // create a sparse index which should have no entries t.ensureIndex( { x:1 }, { sparse: true } ); assert.eq( 0, t.find( { i: 1 } ).hint( "x_1" ).count(), "A" ); assert.eq( 0, t.find( { i: 1 } ).hint( {x: 1} ).length(), "B" ); // With just find works assert.eq( 0, t.find( { i: 1 } ).hint( {x: 1} ).count(), "C" ); // Fails

      When using hint() with count() it only works with the string name of the index and not a document representing the index key.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            ross@mongodb.com Ross Lawley
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: