Giter VIP home page Giter VIP logo

Comments (2)

Simran-B avatar Simran-B commented on July 4, 2024

This is the expected behavior. With OPTIONS {"mergeObjects": false}, the attributes you specify will be set to the specified values. Attributes you don't specify remain, regardless of mergeObjects. If you want to remove attributes selectively, set them to null in an UPDATE operation with OPTIONS { keepNull: false }:

UPDATE { _key: "C", test2: null } IN Client OPTIONS { keepNull: false }

Or you can consider specifying all attributes of the document you want to keep and use a REPLACE operation, but be careful not to remove more attributes than desired - only the ones stated in the query plus immutable system attributes will remain.

from arangodb.

jsteemann avatar jsteemann commented on July 4, 2024

Hi @konsultaner, the implemented behavior of mergeObjects is

  • for any attributes that are present in the overwrite value but not in the source document:
    • add all attributes to the document which are present in the overwrite value but not in the source document. A special case is when keepNull=false is removed, in which case the attributes which are null in the overwrite attribute value will be removed from the target document.
  • for any attributes that are present in the overwrite value and also in the source document:
    • if mergeObjects=false, overwrite the value of the attribute in the source document with the overwrite attribute value.
    • if mergeObjects=true, overwrite the value of the attribute in the source document with the overwrite attribute value if the attribute value in the source document is not an object (i.e. merging not possible, so we are overwriting).
    • if mergeObjects=true, merge the value of attribute in the source document with the overwrite attribute value if they are both objects (merging possible).

The algorithm is not performed on the very top level (i.e. the source document and the overwrite value). Instead it is performed for every top-level attribute present in the overwrite value individually. When merging two attribute values objects, the merging is also performed recursively using the same algorithm.

I understand that this behavior may not always be the desired behavior, but the merging algorithm shouldn't be changed in an incompatible way to avoid incompatibility. In case a different merging algorithm is needed, there are multiple options:

  • implement the custom merging in the client application (requires fetching the original document first, so may not work for large amounts and is subject to data races if there are other concurrent update operations).
  • implement the custom merging as a new option in the database. This would mean another hard-coded merging algorithm, which may or may not be general enough to suit everyone's needs. Also requires support from all relevant drivers in order to be able to use it properly.
  • implement the custom merging in the AQL query, using built-in AQL functions (example following)
FOR doc IN collection
  REPLACE doc WITH MERGE_RECURSIVE(@update) IN collection

Note that this query is not providing a different merge algorithm, but it may be adjusted to your needs. I currently can't tell what merge algorithm you have in mind.

from arangodb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.