doc_upsert: Create a new document or update an existing one

View source: R/doc_upsert.R

doc_upsertR Documentation

Create a new document or update an existing one

Description

Create a new document or update an existing one

Usage

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

## 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)

ropensci/sofa documentation built on Feb. 7, 2025, 1:31 a.m.