arangodb / arangojs

The official ArangoDB JavaScript driver.
https://arangodb.github.io/arangojs
Apache License 2.0
600 stars 106 forks source link

documentCollection.update not updates an existing value with empty object #733

Closed hasithajayasundara closed 2 years ago

hasithajayasundara commented 3 years ago

I have modified this test as follows to illustrate what I was trying to do.

it("updates the given document", async () => {
      // New person entry
      const data = { potato: "tomato", person: { info: { name: "Jane", age: "10"} } };
      const meta = await collection.save(data, { returnNew: true });
      const doc = meta.new!;
      // Update person entry with {}
      await collection.update(doc, { sup: "dawg", person: {} });
      const newData = await collection.document(doc._key);
      expect(newData).to.have.property("potato").that.equals(doc.potato);
      expect(newData).to.have.property("sup").that.equals("dawg");
      // This fails as update did not update the person to {} but keeps the old value
      expect(newData).to.have.property("person").that.equals({});
 });

Idea is I'm trying to update the person to {} which holds a value of { info: { name: "Jane", age: "10"} } }.

Issue

collection.update does not update the person entry to {} but keeps the old value info: { name: "Jane", age: "10"} }.

meadowsys commented 3 years ago

i think thats intended behavior... maybe modify the js object to have person: {} then replace the object in the database?

pluma commented 2 years ago

Update does a "merge" by default. You probably want to set mergeObjects to false: http://arangodb.github.io/arangojs/7.5.0/modules/_collection_.html#collectionupdateoptions

hasithajayasundara commented 2 years ago

@pluma @autumnblazey thanks for the replies. mergeObjects to false resolved the issues. Closing this.