getLastError's n value now indicates the number of inserts completed.

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 3.1.7
    • Component/s: Write Ops
    • None
    • ALL
    • Hide

      In 3.0:

      > db.foo.drop();
      > db.runCommand({insert: "foo", documents: [ { _id: 1} ]})
      { "ok" : 1, "n" : 1 }
      > db.runCommand({getLastError: 1})
      {
              "connectionId" : 1,
              "n" : 0,
              "syncMillis" : 0,
              "writtenTo" : null,
              "err" : null,
              "ok" : 1
      }
      

      In 3.1:

      > db.foo.drop();
      > db.runCommand({insert: "foo", documents: [ { _id: 1} ]})
      { "ok" : 1, "n" : 1 }
      > db.runCommand({getLastError: 1})
      {
              "connectionId" : 1,
              "n" : 1,
              "syncMillis" : 0,
              "writtenTo" : null,
              "err" : null,
              "ok" : 1
      }
      
      Show
      In 3.0: > db.foo.drop(); > db.runCommand({insert: "foo" , documents: [ { _id: 1} ]}) { "ok" : 1, "n" : 1 } > db.runCommand({getLastError: 1}) { "connectionId" : 1, "n" : 0, "syncMillis" : 0, "writtenTo" : null , "err" : null , "ok" : 1 } In 3.1: > db.foo.drop(); > db.runCommand({insert: "foo" , documents: [ { _id: 1} ]}) { "ok" : 1, "n" : 1 } > db.runCommand({getLastError: 1}) { "connectionId" : 1, "n" : 1, "syncMillis" : 0, "writtenTo" : null , "err" : null , "ok" : 1 }
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      getLastError used to return 0 for "n" after an insert. With the latest 3.1.7 nightly, it is now returning 1 (or presumably, the number of documents inserted).

      I certainly think this is the right value for "n" if we're starting from scratch, but at this point we shouldn't change this behavior as users may be relying on this.

            Assignee:
            David Storch
            Reporter:
            Craig Wilson
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: