Documents are updated by patching their JSON with
value
. Documents are identified by a query
or by _id
's in value
, where the latter takes
precedence. value
can have multiple documents (with
_id
's), which then are iteratively updated.
Arguments
- src
Source object, result of call to any of functions
src_mongo()
,src_sqlite()
,src_elastic()
,src_couchdb()
src_duckdb()
orsrc_postgres()
- key
(character) The name of the container in the database backend (corresponds to
collection
for MongoDB,dbname
for CouchDB,index
for Elasticsearch, and to a table name for DuckDB, SQLite and PostgreSQL)- value
The data to be created in the database: a single data.frame, a JSON string, a list, or a file name or URL that points to NDJSON documents
- query
(character) A JSON query string, see examples. Can use comparisons / tests (
$lt
,$lte
,$gt
,$gte
,$ne
,$in
,$regex
), with logic operators ($and
,$or
,(
,)
), including nested queries, see examples. Specify as'{}'
ifvalue
includes_id
's.- ...
Passed on to functions
elastic::docs_bulk_update()
, andmongolite::mongo()
$update().
Details
Uses native functions in MongoDB (mongolite::mongo()
$update()),
SQLite (jsonb_update()
), DuckDB (jsonb_merge_patch()
),
Elasticsearch (elastic::docs_bulk_update()
);
a plpgsql
function added when calling src_postgres()
,
and a jqr::jqr()
programme for CouchDB.
Examples
if (FALSE) { # \dontrun{
src <- src_sqlite()
docdb_create(src, "mtcars", mtcars)
docdb_update(src, "mtcars", value = mtcars[3, 4:5], query = '{"gear": 3}')
docdb_update(src, "mtcars", value = '{"carb":999}', query = '{"gear": 5}')
docdb_update(src, "mtcars", value = '{"_id":"Fiat 128", "carb":888}', query = '{}')
docdb_get(src, "mtcars")
} # }