title: DynamoDB: Dynamoose update ($PUT default behaviour) not working as expected?
body: <p>I'm trying to implement a PUT (update) API endpoint, passing the primary key of an element as a parameter in the path and the attributes I want to update as parameter in the body. But is not working as expected, instead of updating the attributes of an existing element, is creating a new element in the database with wrong attributes.</p>
  
  <p>As far as I understand from the <a href="https://dynamoosejs.com/api#modelupdatekey-update-options-callback" rel="nofollow noreferrer">Dynamoose API documentation</a>, <code>Model.update(key, update, options, callback)</code> updates and existing item in the table. For example, if we have a Dog model where <code>age</code> is one of the attributes, then this code</p>
  
  <pre><code>Dog.update({ownerId: 4, name: 'Odie'}, {age: 1}, function (err) {
    if(err) { return console.log(err); }
    console.log('Just a puppy');
  })
  </code></pre>
  
  <p>would update the <code>age</code> of a  Dog called 'Odie' with ownerId: 4</p>
  
  <p>Now, I tried to do a similar update for my own API. I have a data model called <code>InvoiceConfig</code> where the primary key corresponds to a unique name/id (string) attribute and contains another attribute called <code>providerVariants</code> (an array of objects)</p>
  
  <p>This is my API definition in swagger:</p>
  
  <pre><code>put:
    description: Updates the invoice config matching the id (providerName)
    operationId: updateInvoiceConfigByName
    consumes:
      - application/json
    produces:
      - application/json
    parameters:
      - name: id
        in: path
        required: true
        type: string
      - name: providerVariants
        description: array of JSON objects
        in: body
        required: true
        schema:
          $ref: "#/definitions/ProviderVariantsDataList"
    responses:
      "200":
        description: A confirmation message
        schema:
          $ref: "#/definitions/ResponseMessage"
      "500":
        description: Error message
        schema:
          $ref: "#/definitions/ErrorResponse"
  </code></pre>
  
  <p>And this is the function that implements the dynamoose update in my code:</p>
  
  <pre><code>updateInvoiceConfigByName: function(req, res) {
     var name = req.swagger.params.id.value;
     var providerVariants = req.body;
     console.log("UPDATE /invoice-config");
  
     InvoiceConfig.update({provideName: name}, providerVariants, function(err) {
        if (err) {
           console.log("Update InvoiceConfig error");
           throw err;
        }
  
        res.status(200).send({ 
           providerName: `${name}`,
           message: 'provider invoice cfg updated'
        });
     });
  }
  </code></pre>
  
  <p>I have an object in the database:</p>
  
  <pre><code>{
      "providerName": "ID01",
      "providerVariants": [
        {
          "displayName": "My 1st Provider ",
          "phone": "915698471",
          "availableTemplates": [
            "default"
          ]
        }
      ]
  }
  </code></pre>
  
  <p>and I try to update it from swagger-ui passing the following paramenters:
   <code>ID01</code> in the endpoint path itself and a modified <code>providerVariants</code> array in the body:</p>
  
  <pre><code>[
     {
        "displayName": "My new name",
        "phone": "913333333",
        "availableTemplates": [
           "default"
        ]
     }
  ]
  </code></pre>
  
  <p>But as I said at the beginning, if I check the contents of my table, I see that the item with providerName "ID01" has not changed, and there is a new item created:</p>
  
  <pre><code>{
      "providerName": {
         "S": "[object Object]"
      }
   }
  </code></pre>
  
  <p>I suspect that in this new object the <code>providerName</code> (primary key) was populated with the <code>providerVariants</code> array, which is totally wrong. Any hints about how to fix this are welcome, I don't know how to proceed with the update. Other endpoints (get, delete, post) in my API are working fine, but I'm blocked with the update/put </p>