Count behaviour with a bad hint is inconsistent

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: 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" );
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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 Marina
              Reporter:
              Ross Lawley
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: