nodbi (version 0.2.0)

docdb_query: Get documents with a filtering query

Description

Get documents with a filtering query

Usage

docdb_query(src, key, query, ...)

Arguments

src

source object, result of call to src

key

(chartacter) A key. ignored for mongo

query

various. see Query section below.

...

Additional named parameters passed on to each package:

What is expected for each source

  • CouchDB: a list, see docs for sofa::db_query()

  • Elasticsearch: query parameters, see elastic::Search(); passed to the query parameter of elastic::Search, thus performs a URI based search where the query is passed in the URI instead of the body. In theory you can instead pass in a JSON or list to the body parameter, but if you want to do complicated Elasticsearch queries you may be better of using elastic package directly

  • MongoDB: query parameters, see mongolite docs for help with searches

Not supported yet

  • Etcd

  • Redis

Details

Note that with etcd, you have to prefix a key with a forward slash.

Examples

Run this code
# NOT RUN {
# CouchDB
(src <- src_couchdb())
if (docdb_exists(src, "mtcars2")) docdb_delete(src, "mtcars2")
invisible(docdb_create(src, key = "mtcars2", value = mtcars))
docdb_exists(src, "mtcars2")
(query <- list(cyl = list("$gt" = 6)))
docdb_query(src, "mtcars2", query = query)

# Elasticsearch
src <- src_elastic()
if (docdb_exists(src, "iris")) docdb_delete(src, "iris")
docdb_create(src, "iris", iris)
docdb_exists(src, "iris")
docdb_query(src, "iris", query = "setosa")
docdb_query(src, "iris", query = "1.5")
docdb_query(src, "iris", query = "Petal.Width:1.5")

# Mongo
src <- src_mongo()
if (docdb_exists(src, "mtcars")) docdb_delete(src, "mtcars")
docdb_create(src, "mtcars", mtcars)
docdb_query(src, query = '{"mpg":21}')
docdb_query(src, query = '{"mpg":21}', fields = '{"mpg":1, "cyl":1}')
# }

Run the code above in your browser using DataLab