immediate collection count doesn't get correct result if new document is inserted

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Cannot Reproduce
    • Priority: Major - P3
    • None
    • Affects Version/s: 3.0.2
    • None
    • ALL
    • Hide

      These steps are not guaranteed to reproduce this bug.

      1) create a collection with a lot of documents named test;
      2) create a index

      db.test.ensureIndex({name: 1}, {background: true});

      3) make sure the index built is done;
      4) insert one more document

      db.test.save({name: 'morgan'});

      5) immediately count documents by

      db.test.count({name: 'morgan'});

      Expected result:
      step 5) should always get correct counting;

      Actual result:
      step 5) has a chance to get wrong counting just like step 4) is not performed.

      Show
      These steps are not guaranteed to reproduce this bug. 1) create a collection with a lot of documents named test; 2) create a index db.test.ensureIndex({name: 1}, {background: true}); 3) make sure the index built is done; 4) insert one more document db.test.save({name: 'morgan'}); 5) immediately count documents by db.test.count({name: 'morgan'}); Expected result: step 5) should always get correct counting; Actual result: step 5) has a chance to get wrong counting just like step 4) is not performed.
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      It is hard to reproduce, but I have this issue identified multiple times in production environment.

      One operation insert a document into a collection host in only one mongod with write concern 1. After got the write success response, a count with condition is issued to the same mongod. Surely, the count response should include the newly-inserted document. However, sometimes it just doesn't have the new document counted.

      Just my guessing: If the indexing of the count condition is performed in background, there is possibility that collection indexing is not updated when insert operation returns OK even with write concern 1. If count operation depends on the index, then a immediate count operation could return result without the newly-inserted document counted.

            Assignee:
            Ramon Fernandez
            Reporter:
            Morgan Cheng
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: