Methods for working with Azure Cosmos DB documents
Methods for working with Azure Cosmos DB documents
get_document(object,...)create_document(object,...)## S3 method for class 'cosmos_container'create_document(object, data, headers = list(),...)list_documents(object,...)## S3 method for class 'cosmos_container'list_documents( object, partition_key =NULL, as_data_frame =FALSE, metadata =TRUE, headers = list(),...)delete_document(object,...)## S3 method for class 'cosmos_container'delete_document( object, id, partition_key, headers = list(), confirm =TRUE,...)## S3 method for class '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.
Returns
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.
Examples
## 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 objectslist_documents(cont)# a data framelist_documents(cont, as_data_frame=TRUE)# a single documentdoc <- get_document(cont,"mydocumentid")doc$data
delete_document(doc)## End(Not run)