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

Add a 'initial value' parameter to $inc

    • Type: Icon: New Feature New Feature
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Write Ops
    • None
    • Query

      $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.

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

              Created:
              Updated:
              Resolved: