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

update using $inc returns value incremented to

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      Currently we can do:

      foo=db.kg.findAndModify({query:

      {"dogs":2}

      ,update:{$inc:

      {"dogs":1}

      }})

      { "_id" : ObjectId("4bc665954c25a502cc9c76ef"), "dogs" : 2 }

      foo

      { "_id" : ObjectId("4bc665954c25a502cc9c76ef"), "dogs" : 2 }

      db.kg.find()

      { "_id" : ObjectId("4bc665954c25a502cc9c76ef"), "dogs" : 3 }

      I think this would be nicer:

      foo=db.kg.update({},{$inc:{"dogs":1}} )
      foo

      {"dogs":4}

      and perhaps even:

      foo=db.kg.update({},{$inc{"dogs":1}},{$inc{"cats":1}})
      foo

      {"dogs":5,"cats":2}

      Returning the incremented value allows applications to use the newly generated value

      Attachments

        Activity

          People

            eliot Eliot Horowitz (Inactive)
            kgorman Kenny Gorman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: