Managing JSON Documents
To perform CRUD operations (create, read, update, and delete) on JSON documents in
HPE Data Fabric Database JSON tables using the OJAI API, you use Document,
DocumentStore, and DocumentMutation objects.
You can also perform these operations using HPE Data Fabric Database Shell (JSON Tables).
Document
To create a JSON document, you must create a Document
object. See the following for information specific to each language:
To create a JSON document in Java OJAI, use the Document interface.
See Creating JSON Documents in Java OJAI to learn about the different ways to create Document objects in
Java.
To create a Document object in Node.js OJAI, simply create a JSON
object.
See Sample OJAI Code for Creating JSON Documents for an example of how to do this.
The preferred approach is to create a Document object in Python is
to create a Python dictionary. You can also use the Document interface.
See Creating JSON Documents in Python OJAI to learn about these two ways to create JSON documents in Python.
To create a Document object in C# OJAI, create a C# object.
See Sample OJAI Code for Creating JSON Documents for an example of how to do this.
For C# OJAI examples, see this Github page.
To create a Document object in Go OJAI, create a Go structure.
See Sample OJAI Code for Creating JSON Documents for an example of how to do this.
DocumentStore
After you create a Document object, you can pass it to the
DocumentStore interface. The interface has methods to perform the
following tasks:
- Delete documents from tables
- Insert documents into tables
- Replace documents in tables
See the following for API links to the DocumentStore
interface in each language:
ojai.mapr.documentstore.buffer-writes option and with the
Document object. This option is available only in the Java OJAI
API. See Enabling Buffered Writes in Java OJAI for more information.For C# OJAI examples, see this Github page.
DocumentMutation
To make
changes to JSON documents, create a DocumentMutation object. A
DocumentMutation enables you to perform OJAI mutations, which includes
replacing, updating, combining, and deleting fields in a JSON document. For a list of
available mutations, see Using OJAI Mutation Syntax.
To create a DocumentMutation object, call the methods in the
DocumentMutation class corresponding to the mutation operations you
want to perform. See DocumentMutation for a list of available
methods.
Pass the DocumentMutation object to either the DocumentStore.checkAndUpdate or DocumentStore.update method to apply the changes to the document.
The first method accepts a QueryCondition parameter that must
evaluate to true for the mutation to be applied. Both methods have an
_id parameter corresponding to the document to be updated.
To create a DocumentMutation object, create a JSON object Using OJAI Mutation Syntax.
Pass the DocumentMutation object to either the DocumentStore.checkAndUpdate or DocumentStore.update method to apply the changes to the
document. The DocumentStore.checkAndUpdate() method accepts an OJAI
query condition parameter that must evaluate to true for the mutation to be applied.
Both methods have an _id parameter corresponding to the document to
be updated.
To create a DocumentMutation object, create a Python dictionary
object Using OJAI Mutation Syntax.
Pass the DocumentMutation object to either the DocumentStore.check_and_update or DocumentStore.update method to apply the changes to the
document. The DocumentStore.check_and_update() method accepts an OJAI
query condition parameter that must evaluate to true for the mutation to be applied.
Both methods have an _id parameter corresponding to the document to
be updated.
To create a DocumentMutation object, create a C# object Using OJAI Mutation Syntax.
Pass the DocumentMutation object to either the DocumentStore.CheckAndUpdate or
DocumentStore.Update method to
apply the changes to the document. The DocumentStore.CheckAndUpdate method
accepts an OJAI query condition parameter that must evaluate to true for the mutation
to be applied. Both methods have an _id parameter corresponding to
the document to be updated.
For C# OJAI examples, see this Github page.
To create a DocumentMutation object, create a Go structure Using OJAI Mutation Syntax.
Pass the DocumentMutation structure to either the DocumentStore.CheckAndUpdate or
DocumentStore.Update method to
apply the changes to the document. The DocumentStore.CheckAndUpdate method
accepts an OJAI query condition parameter that must evaluate to true for the mutation
to be applied. Both methods have an _id parameter corresponding to
the document to be updated.
By default, the default maximum size of a JSON document is 32 MB. A
DocumentMutation does not enforce this limit. HPE Data Fabric Database enforces the limit
when you pass your DocumentMutation object to the
DocumentStore method. See JSON Document Size for information about how
to increase this limit.
See Examples: Updating JSON Documents for examples that use mutations.