Skip to content

Strict add operator #3

Open
Open

Description

@mnot

( from John Huffaker)

In concurrent modification scenarios test plus add/replace work great to avoid one user silently overwriting another user's modifications. The problem occurs when two users try to both add the same key (with different values) concurrently.

The test operator can't check for non-existence and their is no strict add operator that fails if the key already exists. I could resort to some other form of course grained locking but I really like the fine grained optimistic locking allowed by the current spec. Is a strict add operator on the horizon or should we add a non-standard operator to handle our use-case?

Activity

  1. huggsboson commented on May 8, 2014

    @huggsboson

    s/their/there. [ashamed face]

  2. briancavalier commented on May 8, 2014

    @briancavalier

    I'm generally +1 on this as well. While the "add-acts-like-replace-for-existing-keys" behavior can be convenient in some cases, it also means that add has at least 2 possible inverses: remove and replace (ie did it add or did it replace??). In fact, one could say that it has 3, since add itself, when used like replace could be an inverse of add!

    It makes #2 much easier if add has only 1 inverse.

  3. espadrine commented on Aug 23, 2016

    @espadrine

    This feels similar to the upsert problem, reversed. Most database systems offer insert and update, but no upsert (aka "update if it exists, insert if not"). JSON Patch has upsert (add) and update (replace), but no insert — which could therefore be the operation name.

    As a side-note, this is addressed by #14 as well.

  4. streamich commented on Sep 3, 2020

    @streamich

    This can be achieved using JSON Predicate undefined operation. For example:

    [
      {"op": "undefined", "path": "/foo"},
      {"op": "add", "path": "/foo", "value": "bar"}
    ]

    I've implemented it in json-joy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions