Concourse provides several methods for writing data to records. All
write operations are atomic by default — when operating outside
of an explicit transaction, each individual write
is automatically committed.
The add method appends a value to a field if and only if that
value does not already exist in the field. A field in Concourse can
hold multiple distinct values simultaneously, so add is the
primary way to build up multi-valued fields.
You can add a value across several records at once. The method
returns a Map associating each record ID to a boolean indicating
whether the add succeeded for that record.
The set method atomically removes all existing values for a key
in a record and then adds a new value. Use set when a field
should contain exactly one value.
The clear method atomically removes all values stored for one
or more keys in one or more records. Use this to completely wipe
a field or an entire record.
The insert method atomically writes a collection of key/value
associations into one or more records. This is the most efficient
way to load structured data into Concourse.
Pass a JSON string containing a top-level object to insert a
single record, or a top-level array of objects to insert multiple
records. The method returns the set of record IDs where the data
was inserted.
You can insert data into specific existing records. The insert
will fail for a given record if any of the key/value associations
already exist in that record.
When inserting JSON or Map data, you can include resolvable link
instructions that automatically create links to all records
matching a criteria. Use Link.toWhere(criteria) to generate the
instruction.
Resolvable links should only be used within insert
operations (JSON, Map, or Multimap). Do not use add to
write resolvable links because the evaluation and linking
would not be atomic.
Atomically verify that a key contains exactly one specific value
in a record, or set it as such. After this method returns, the
field is guaranteed to contain only the specified value.
Unlike set, verifyOrSet does not create new revisions unless
necessary. If the field already contains exactly the specified
value and nothing else, no changes are made.
Make the necessary changes so that a field contains exactly the
specified collection of values. Concourse computes the minimal
diff and only applies the adds and removes needed.
Atomically find the unique record where a key equals a value, or
add the key/value pair to a new record if none exists. Throws a
DuplicateEntryException if more than one record matches.
1234
// Javalongrecord=concourse.findOrAdd("email","jeff@cinchapi.com");// Returns the existing record, or creates a new one
Atomically find the unique record matching a criteria, or insert
data into a new record if none exists. This is the most flexible
way to implement upsert semantics.
Like insert, the data parameter can be a JSON string, Map, or
Multimap.
DuplicateEntryException
Both findOrAdd and findOrInsert throw a
DuplicateEntryException if more than one record matches the
condition. This ensures the uniqueness guarantee is enforced.
Design your criteria to match at most one record.
The consolidate method merges the data from two or more records
into a single record. After consolidation, the surviving record
contains the union of all values from the merged records, and the
other records are cleared.
123
// Javaconcourse.consolidate(1,2,3);// All data from records 2 and 3 is merged into record 1