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

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

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 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 }

      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@mongodb.com David Storch
            Reporter:
            craig.wilson@mongodb.com Craig Wilson
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: