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

Update / findAndModify with {upsert: true} should report nMatched:0 nModified:0 if results in an insert

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.2
    • Affects Version/s: 2.6.11, 3.0.7, 3.2.0
    • Component/s: Diagnostics, Write Ops
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Query F (02/01/16)

      Consider an update operation with the {upsert: true} flag whose query predicate does not match any of the documents in the collection:

      db.setLogLevel(1);
      db.c.drop();
      db.c.insert({a: 1});
      db.c.update({a: 2}, {$set: {b: 1}}, {upsert: true});
      

      This update operation does not match any documents, nor does it modify any existing documents, but in nonetheless generates the following log line:

      2015-12-09T14:06:02.569-0500 I WRITE    [conn1] update test.c query: { a: 2.0 } update: { $set: { b: 1.0 } } keysExamined:0 docsExamined:1 nMatched:1 nModified:1 upsert:1 keyUpdates:0 writeConflicts:0 numYields:0 locks:{ Global: { acquireCount: { r: 1, w: 1 } }, Database: { acquireCount: { w: 1 } }, Collection: { acquireCount: { w: 1 } } } 0ms
      

      Instead of nMatched:1 and nModified:1 this should report nMatched:0 and nModified:0. This applies to both update and findAndModify for both the log and the profile collection.

            Assignee:
            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: