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

Add a 'initial value' parameter to $inc

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed
    • Major - P3
    • Resolution: Won't Do
    • None
    • None
    • Write Ops
    • None

    Description

      $inc is great to increment an existing field by a given amount, however for a newly created document you should be able to set the initial value for the field, rather than to assume it should be the same as the increment value.

      Change

      { $inc: { <field1>: <amount1>, <field2>: <amount2>, ... } } 
      

      To

      { $inc: { <field1>: {start:<value1>, next:<amount1},
                   <field2>:  {start:<value2>, next:<amount2}, ... } } 
      

      This need became apparent when using upsert = true on an update with a field that is normally incremented if it exists, but should have a user defined starting value when it does not.

      Attachments

        Issue Links

          Activity

            People

              backlog-server-query Backlog - Query Team (Inactive)
              ensefik Edem Nsefik
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: