Legacy
Documents and IDs (Legacy)
ditto is a nosql database that organizes json like documents into collections unlike json, with ditto you can apply updates directly to the document, ensuring sync across all connected peers additionally, it offers support for various data types for an overview of the data types you can use in ditto, see the platform manual > docid\ eabfh8r9iou8z col8zkh a document serves as a schema flexible unit of data if collections are compared to tables, a document can be compared to a row each document at its core is a map capable of holding fields and embedded key value pairs every document is assigned a primary key, referred to as a document id for more information about ditto documents, see platform manual > docid\ mpzz3whdaqmllroaoyofc primary key document id https //legacydocs ditto live/http/common/concepts/documents#primary key id the ditto query engine supports various filter operations for optimal data retrieval as the basis of data organization and access in ditto, the query engine indexes the document id so you can quickly and precisely access your data when invoking the upsert method to create a new document, unless manually supplied, ditto automatically generates and assigns the new document a 128‑bit universally unique identifier (uuid) when referencing the document id in your queries for the http api, pass id instead of the reserved id parameter however, if not making api calls, pass the reserved id instead custom document id if supplying your own document id, you can encode your value in a string or, if forming a composite key, a json object you can configure a custom document id only at the time of document creation once a document is created, to ensure consistency and uniqueness throughout the platform, the unique identifier that either ditto automatically generated and assigned or you manually assigned becomes permanent and cannot be changed at a later time the decision to opt for a composite key depends on your specific use case following are typical use cases for forming a composite key to implement additional logic to handle (or prevent) duplicate writes to simplify queries and enhance efficiency in the querying process supplying a string id to provide a custom document id, when invoking upsert to create a new document, include the id parameter with a string set to the value you want to use as the document's id for example, the following snippet demonstrates creating a new document in the people collection with the custom id set to abc123 , along with the specified name and age values curl curl x post 'https //\<cloud endpoint>/api/v4/store/write' \\ \ header 'content type application/json' \\ \ data raw '{ "commands" \[{ "method" "upsert", "collection" "people", "id" "abc123", "value" { "name" "susan", "age" 31 } }] }' forming a composite key to form a composite key, when calling upsert to create a new document, pass the fields you want to combine to form the new primary key in an embedded map structure under the id field for example, the following snippet shows an upsert operation on the people collection forming a composite key made up of two parts string integer ditto compares document ids based on the combination of keys and their corresponding values, not by literal order in which the key value pairs are defined therefore, if two document ids have the same key value pairs, they will be considered equal for example {a "foo", b 1} == { b 1, a "foo" } curl curl x post 'https //\<cloud endpoint>/api/v4/store/write' \\ \ header 'content type application/json' \\ \ data raw '{ \[{ "method" "upsert", "collection" "people", "id" { "user id" "456abc", "work id" 789 }, "value" { "name" "susan", "age" 31 } }] }'