docdb_query | R Documentation |
Get documents or parts with filtering query
docdb_query(src, key, query, ...)
src |
Source object, result of call to any of functions
|
key |
(character) The name of the container in the
database backend
(corresponds to |
query |
(character) A JSON query string, see examples. Can use comparisons / tests (e.g., '$gt', '$ne', '$in', '$regex'), with at most one logic operator ('$and' if not specified, or '$or'), see examples. |
... |
Optionally, specify |
Data frame with requested documents, may have nested
lists in columns. If query = "{}"
and fields are not
specified, consider using docdb_get()
.
A dot in query
or fields
is interpreted as a dot path;
it is not supported to have a dot within the key / name of a field.
Main functions used per database:
MongoDB: find() in mongolite::mongo()
SQLite: SQL query using built-in json_tree()
Elasticsearch: elastic::Search()
CouchDB: sofa::db_query()
PostgreSQL: SQL query using built-in jsonb_build_object()
DuckDB: SQL using built-in json_extract()
## Not run:
src <- src_sqlite()
docdb_create(src, "mtcars", mtcars)
docdb_query(src, "mtcars", query = '{"mpg":21}')
docdb_query(src, "mtcars", query = '{"mpg":21, "gear": {"$lte": 4}}')
docdb_query(src, "mtcars", query = '{"mpg":21}', fields = '{"_id":0, "mpg":1, "cyl":1}')
docdb_query(src, "mtcars", query = '{"_id": {"$regex": "^.+0.*$"}}', fields = '{"gear": 1}')
# complex query, not supported for src_elastic and src_couchdb backends at this time:
docdb_query(src, "mtcars", query = '{"$and": [{"mpg": {"$lte": 18}}, {"gear": {"$gt": 3}}]}')
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.