AzureCosmosR (version 1.0.0)

get_document: Methods for working with Azure Cosmos DB documents

Description

Methods for working with Azure Cosmos DB documents

Usage

get_document(object, ...)

create_document(object, ...)

# S3 method for cosmos_container create_document(object, data, headers = list(), ...)

list_documents(object, ...)

# S3 method for cosmos_container list_documents( object, partition_key = NULL, as_data_frame = FALSE, metadata = TRUE, headers = list(), ... )

delete_document(object, ...)

# S3 method for cosmos_container delete_document( object, id, partition_key, headers = list(), confirm = TRUE, ... )

# S3 method for cosmos_document delete_document(object, ...)

Arguments

object

A Cosmos DB container object, as obtained by get_cosmos_container or create_cosmos_container.

data

For create_document, the document data. This can be either a string containing JSON text, or a (possibly nested) list containing the parsed JSON.

headers, ...

Optional arguments passed to lower-level functions.

partition_key

For get_document and delete_document, the value of the partition key for the desired document. For list_documents, restrict the returned list only to documents with this key value.

as_data_frame

For list_documents, whether to return a data frame or a list of Cosmos DB document objects. Note that the default value is FALSE, unlike query_documents.

metadata

For get_document and list_documents, whether to include Cosmos DB document metadata in the result.

id

The document ID.

confirm

For delete_cosmos_container, whether to ask for confirmation before deleting.

Value

get_document and create_document return an object of S3 class cosmos_document. The actual document contents can be found in the data component of this object.

list_documents returns a list of cosmos_document objects if as_data_frame is FALSE, and a data frame otherwise.

Details

These are low-level functions for working with individual documents in a Cosmos DB container. In most cases you will want to use query_documents to issue queries against the container, or bulk_import and bulk_delete to create and delete documents.

See Also

query_documents, bulk_import, bulk_delete, cosmos_container

Examples

Run this code
# NOT RUN {
endp <- cosmos_endpoint("https://myaccount.documents.azure.com:443/", key="mykey")
db <- get_cosmos_database(endp, "mydatabase")

cont <- get_cosmos_container(db, "mycontainer")

# a list of document objects
list_documents(cont)

# a data frame
list_documents(cont, as_data_frame=TRUE)

# a single document
doc <- get_document(cont, "mydocumentid")
doc$data

delete_document(doc)

# }

Run the code above in your browser using DataLab