Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-4968

findAndModify no longer changes return behavior depending on if a sort was specified

    XMLWordPrintableJSON

Details

    Description

      The 3.0 docs for findAndModify have a section on the output of the command, and then a subsection with a note. In that note, the last two bullet points no longer apply.
      E.g.

      > db.foo.drop()
      true
      > db.runCommand({findAndModify: 'foo', query: {_id: 'doc_with_sort'}, update: {$inc: {i: 1}}, upsert: true, new: false, sort: {_id: -1}})
      {
      	"value" : null,
      	"lastErrorObject" : {
      		"updatedExisting" : false,
      		"n" : 1,
      		"upserted" : 'doc_with_sort'
      	},
      	"ok" : 1
      }
      > db.runCommand({findAndModify: 'foo', query: {_id: 'doc_without_sort'}, update: {$inc: {i: 1}}, upsert: true, new: false})
      {
      	"value" : null,
      	"lastErrorObject" : {
      		"updatedExisting" : false,
      		"n" : 1,
      		"upserted" : 'doc_without_sort'
      	},
      	"ok" : 1
      }
      

      Notice both with and without the sort parameter, value is null.

      Attachments

        Activity

          People

            andrew.aldridge@mongodb.com Andrew Aldridge
            charlie.swanson@mongodb.com Charlie Swanson
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              8 years, 20 weeks, 1 day ago