v0.7.0

Writing JSON Fields

Last updated


This page explains how ToriiDB sets, increments, and deletes individual fields inside a stored JSON document.

Writing Fields


  1. SET user.profile.level 2
  2. SET user.profile.active true
  3. SET user.tags.1 database
  4. SET user.meta {"source":"import"}

The value text is converted with utils.Atov:
TextStored as
nullJSON null (deletes the field when the parent is an object)
true / falseboolean
integer / floatnumber
{...} / [...] that parsesobject / array
anything elsestring

SituationResult
Key missingA new object is created
Key holds non-JSONFails: not JSON type
Key holds a top-level arrayReplaced by a new object containing only the written path
Intermediate field missingAn empty object is created
Intermediate field is a scalarFails
Array index out of range or not a numberFails; arrays are never extended
NX / XXChecked against the top-level key
Trailing secondsSets expiry; without it an existing expiry stays in memory, but the appended log record carries no expiry, so replaying that log (after a crash, before the next compaction) leaves the key without a TTL
VECTORRejected: error: VECTOR not supported on field-level SET

Numeric Fields


  1. INCR user.profile.level
  2. INCR user.profile.score 0.5

IncrField needs a top-level object and an existing numeric field, adds the delta, rewrites the document with setParsed, and appends the full document to the log. Missing fields and non-numeric values fail without creating anything.

Deleting Fields


  1. DEL user.profile.active

Only a single dotted argument deletes a field; DEL a.b c deletes the top-level keys a.b and c. DelField needs a top-level object. An object field is removed; an array element is set to null instead of shrinking the array. Missing intermediate objects on the path are created as empty objects before the delete.

中文