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

Count behaviour with a bad hint is inconsistent

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.6.4
    • Component/s: Querying
    • None
    • ALL
    • Hide
      collection = db.jstests_count_hint;
      collection.drop();
      
      assert.throws( function() { collection.find( { i: 1 } ).hint( "BAD HINT" ).count(); }, [], "A");
      assert.throws( function() { collection.find().hint( "BAD HINT" ).count(); }, [], "B");
      
      collection.save({i: 1});
      assert.throws( function() { collection.find({ i: 1 }).hint( "BAD HINT" ).count(); }, [], "C");
      
      Show
      collection = db.jstests_count_hint; collection.drop(); assert . throws ( function() { collection.find( { i: 1 } ).hint( "BAD HINT" ).count(); }, [], "A" ); assert . throws ( function() { collection.find().hint( "BAD HINT" ).count(); }, [], "B" ); collection.save({i: 1}); assert . throws ( function() { collection.find({ i: 1 }).hint( "BAD HINT" ).count(); }, [], "C" );

      Running a count with an invalid hint may or may not error.

      1. If there are no documents in the collection it won't error
      2. If there are documents but no filter it won't error
      3. If there are documents and a filter it will error

      collection = db.jstests_count_hint;
      collection.drop();
      
      assert.throws( function() { collection.find( { i: 1 } ).hint( "BAD HINT" ).count(); }, [], "A");
      assert.throws( function() { collection.find().hint( "BAD HINT" ).count(); }, [], "B");
      
      collection.save({i: 1});
      assert.throws( function() { collection.find({ i: 1 }).hint( "BAD HINT" ).count(); }, [], "C");
      

      Only "C" will error.

            Assignee:
            ramon.fernandez@mongodb.com Ramon Fernandez Marina
            Reporter:
            ross@mongodb.com Ross Lawley
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: