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

findAndModify() and getLastError() Problem

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Works as Designed
    • 1.6.5
    • None
    • None
    • None
    • Mac OS X 10.6.6; MongoDB 1.6.5
    • Fully Compatible
    • ALL

    Description

      When using the "findAndModify" command, "getLastError" only returns the result of the last of the two operations. By default, this means it returns the result of the "update" operation (which is normally desirable), but when one uses the "new" option, getLastError returns the result of the "find" operation, so any error in the update clause is inaccessible.

      The following sequence of commands demonstrates the problem:
      db.test.insert(

      {name: 'bob'}

      )
      db.test.findAndModify({query:

      {name: 'bob'}

      , update: {$set:

      {age: 30}

      , $inc: {age: 3}}, new: true})
      db.getLastError()

      Ideally, what you should receive when you run the last line, db.getLastError(), you should get an error "Field name duplication not allowed with modifiers". Instead, you get null, as the find operation (the 2nd of the two internal operations), succeeded. If you had the "new" option set to false, and you had a similar error in the find/query portion of the command, you'd get the same problem.

      Attachments

        Activity

          People

            Unassigned Unassigned
            wardrop Tom Wardrop
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: