◷ Reading Time: 1 minute
Create Document
Creates a document in your collection.
- Data Source (required): connection string to your collection.
E.g.endpoint=YourEndpoint;masterKey=YourMasterKey;database=YourDatabaseName;collection=YourCollectionName
- Document Content (required): your JSON document’s content.
- Partition Key: The partition key value if required by your collection.
- Dynamically specify the key. E.g.
@.LastName
. - Explicitly specify the key. E.g.
"Andersen"
. - Alternatively, you can pass the partition key in your Data Source.
- Dynamically specify the key. E.g.
Create Document
1. Add a Create Document activity to your flow.

2. Set the arguments.
Enter the Data Source. The example below uses a database called FrsSchoolDatabase, and a container called StaffContainer.

Enter the Document Content as a JSON object.

Enter the Partition Key. This example uses a dynamic partition key which will grab the partition key value from the Document Content.

3. Execute your flow and browse to your Cosmos DB container to see your document created in the container.

Query Database
Runs a SQL query against the documents in your collection.
- Data Source (required): connection string to your collection.
E.g.endpoint=YourEndpoint;masterKey=YourMasterKey;database=YourDatabaseName;collection=YourCollectionName
- SQL Query (required): CosmosDB compatible SQL query to run.
- Partition Key: The partition key to use for your document.
- Dynamically specify the key. E.g.
@.LastName
. - Explicitly specify the key. E.g.
"Andersen"
. - Alternatively, you can pass the partition key in your Data Source.
- Dynamically specify the key. E.g.
- returns: JSON of query results.
Query Database
In this example, we’re using a collection with two documents inside. We will execute a query against this collection to read the two documents.

1. Create a variable to store your results.
Click on the icon, Variable Parameters.

Create a local variable called results with the JSON Type and click OK.

2. Add a Query Database activity to your flow.

3. Set the arguments.
Enter the Data Source. The example below uses a database called FrsSchoolDatabase, and a container called StaffContainer.

Enter the SQL Query you want to execute. In this example, we’ll select all the documents in the container.

Enter the Partition Key. If you do not enter a Partition Key, a cross-partition query will be executed. In this example, we will not enter a Partition Key.

Enter the variable created in step 1 to your Copy Result To.

4. Run your flow in debug mode. Once you pass the Query Database activity, you should be able to see two documents loaded into the results variable.

Update Document
Updates a document in your collection.
- Data Source (required): connection string to your collection.
E.g.endpoint=YourEndpoint;masterKey=YourMasterKey;database=YourDatabaseName;collection=YourCollectionName
- Document Content (required): your JSON document’s content.
- Document ID (required): The document ID for your document in the collection.
- Partition Key: The partition key to use for your document.
- Dynamically specify the key. E.g.
@.LastName
. - Explicitly specify the key. E.g.
"Andersen"
. - Alternatively, you can pass the partition key in your Data Source.
- Dynamically specify the key. E.g.
Update Document
Our Cosmos DB container has a document that we created in an earlier example. We will update the name for the document in this example.

1. Add an Update Document activity to the flow.

2. Set the arguments.
Enter the Data Source. The example below uses a database called FrsSchoolDatabase, and a container called StaffContainer.

Enter the Document Content as a JSON object.

Enter the Document ID.

Enter the Partition Key. This example uses a static value that needs to be wrapped in quotation marks.

3. Execute your flow and browse to your Cosmos DB container to see the change made to your document which should have the name changed.

Delete Document
Deletes a document in your collection.
- Data Source (required): connection string to your collection.
E.g.endpoint=YourEndpoint;masterKey=YourMasterKey;database=YourDatabaseName;collection=YourCollectionName
- Document ID (required): The document ID for your document in the collection.
- Partition Key: The partition key to use for your document.
- Dynamically specify the key. E.g.
@.LastName
. - Explicitly specify the key. E.g.
"Andersen"
. - Alternatively, you can pass the partition key in your Data Source.
- Dynamically specify the key. E.g.
Delete Document
Our Cosmos DB container has a document that we created in an earlier example. We will delete this document in this example.

1. Add a Delete Document activity to your flow.

2. Set the arguments.
Enter the Data Source. The example below uses a database called FrsSchoolDatabase, and a container called StaffContainer.

Enter the Document ID.

Enter the Partition Key. This example uses a static value.

3. Execute your flow and browse to your Cosmos DB container to see that the document has been deleted.
