doc_upsert: Create a new document or update an existing one

Description Usage Arguments Details Value Author(s) Examples

View source: R/doc_upsert.R

Description

Create a new document or update an existing one

Usage

1
doc_upsert(cushion, dbname, doc, docid)

Arguments

cushion

A Cushion object. Required.

dbname

(character) Database name. Required.

doc

(character) Document content. Required.

docid

(character) Document ID. Required.

Details

Internally, this function attempts to update a document with the given name.
If the document does not exist, it is created

Value

JSON as a character string or a list (determined by the as parameter)

Author(s)

George Kritikos

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 
user <- Sys.getenv("COUCHDB_TEST_USER")
pwd <- Sys.getenv("COUCHDB_TEST_PWD")
(x <- Cushion$new(user=user, pwd=pwd))

if ("sofadb" %in% db_list(x)) {
  invisible(db_delete(x, dbname="sofadb"))
}
db_create(x, 'sofadb')

# create a document
doc1 <- '{"name": "drink", "beer": "IPA", "score": 5}'
doc_upsert(x, dbname="sofadb", doc1, docid="abeer")

#update the document
doc2 <- '{"name": "drink", "beer": "lager", "score": 6}'
doc_upsert(x, dbname="sofadb", doc2, docid="abeer")


doc_get(x, dbname = "sofadb", docid = "abeer")

## End(Not run)

sofa documentation built on July 8, 2020, 6:53 p.m.