Azure Cosmos DB

◷ Reading Time: 2 minutes

cosmosCreate

Creates a document in your collection.

 cosmosCreate (connection, payload, partitionKey)
  • connection: connection string to the Cosmos DB collection.
  • payload: json content of the document to be created.
  • partitionKey: key to filter partitions in the collection.

cosmosQuery

Runs a SQL query against the documents in your collection.

documents |cosmosQuery (connection, query, partitionKey)
  • connection: connection string to the Cosmos DB collection.
  • query:
    • Cosmos DB compatible SQL string query.
    • An object representing the statement structure as below
      • for stored procedure execution {sp: string, inputs: array}
        When there are no inputs needed, inputs should not be provided.
      • for query execution {query:string}
  • partitionKey: key to filter partitions in the collection. When this parameter is not provided, the query will be considered as a cross-partition query.

Examples:
In the below examples, cnn is a parameter that holds the connection string.

Example 1: Querying consmosDB with a plain query statement:

documents |cosmosQuery(cnn, 'SELECT * FROM root')

Example 2: Executing a stored procedure on consmosDB with input values:

documents |cosmosQuery(cnn, 
                 {
                  sp:'customers_invoice_report', 
                  inputs:[24,679,1030]
                 }
           )

cosmosUpdate

Updates a document in your collection.

 cosmosCreate (connection, payload, documentId, partitionKey)
  • connection: connection string to the Cosmos DB collection.
  • payload: json content of the document to be updated..
  • documentId: Identifier of the document to be updated.
  • partitionKey: key to filter partitions in the collection.

cosmosDelete

Deletes a document in your collection.

 cosmosDelete (connection, documentId, partitionKey)
  • connection: connection string to the Cosmos DB collection.
  • documentId: Identifier of the document to be deleted.
  • partitionKey: key to filter partitions in the collection.
Updated on October 5, 2020

Was this article helpful?

Related Articles