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

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

    XMLWordPrintableJSON

Details

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

    Description

      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.

      Attachments

        Activity

          People

            david.storch@mongodb.com David Storch
            craig.wilson@mongodb.com Craig Wilson
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: