fogine / couchbase-odm

CouchbaseODM is a promise-based Node.js ODM for Couchbase
https://fogine.github.io/couchbase-odm
MIT License
12 stars 3 forks source link

Update method not working as expected #22

Closed mreis92 closed 7 years ago

mreis92 commented 7 years ago

Hello! I have a property on my schema which is a DataTypes.ARRAY, of strings. I wanted to update this array by adding or removing new strings, but update only works for adding new strings.

What you are doing?

let updatedUser = { myArray: [] };

User.getById(id).then((user) => {
  //user has the property myArray as ["test"]

  return user.update(updatedUser);
});

What do you expect to happen?

I wanted the user to have an empty array for myArray.

What is actually happening?

Nothing - the elements are not being removed, only added if I try so.

Couchbase SDK version: 2.2.3 Couchbase Server version: 4.1.0 Community CouchbaseODM version/branch: develop

Let me know if you need more information. Thank you!

fogine commented 7 years ago

Hello @mreis92 ,

the fix is available on the develop branch. When you do user.update(updatedData), document's data properties are overridden by assignment by those properties from the updatedData object. There is no recursive merge anymore.