Learn to use Cosmos Database Operations
Do you need a highly scalable and globally distributed NoSQL database for your modern application? Look no further than Azure Cosmos DB!
In this blog post, we will dive into the various operations you can perform on Azure Cosmos DB using the Zeromagic platform. Whether you need to create, read, update, or delete data, Zeromagic provides a set of predefined actions to help you manage your database efficiently. These operations include CreateOne, CreateMany, ReadOne, ReadMany, DeleteOne, DeleteMany, UpdateOne, UpdateMany, and Custom Filter queries. Let’s explore each operation in detail to understand how you can use them to manage your Cosmos DB effectively.
Reference
Check here to learn more about Zeromagic Query Language
Login to Zeromagic Platform and go to you Project Console
. Now navigate to Modules
in the sidebar of the console. Click on the necessary Module and navigate to the Flow Builder Page.
1. CreateOne
The CreateOne
operation allows you to insert a single document into your Cosmos DB container. This is useful when you need to add individual records to your database.
- Add a CreateOne block to your workflow. Set the
record to add
field to{{$request.body}}
so as to specify the data that will be used to create the new record. - In the
Http Response
block , set theResponse Variable
field to expression as{{$block-name.val}}
.
Sample Data
2. CreateMany
The CreateMany
operation enables you to insert multiple documents at once. This is ideal for batch operations where you need to add several records simultaneously.
- Add a CreateMany block to your workflow. Set the
Create Value
field to{{$request.body.<key>}}
so as to specify the data that will be used to create the new record. - In the
Http Response
block , set theResponse Variable
field to expression as{{$block-name.val}}
.
Sample Data
3. ReadOne
The ReadOne
operation allows you to retrieve a single document based on its unique identifier. This is useful when you need to fetch specific records.
- Add a ReadOne block to your workflow. Set the
Record Id
field to{{$request.body.id}}
so as to specify the data that will be used to create the new record. - In the
Http Response
block , set theResponse Variable
field to expression as{{$block-name.val}}
.
Sample Data
4. ReadMany
The ReadMany
operation lets you fetch multiple documents that match a given criteria. This is beneficial for retrieving a set of records based on certain conditions.
-
Add a ReadMany block to your workflow. Set the
Sort Key
field to name, which corresponds to the data key in the schema, and choose eitherasc
ordesc
for theSort Order
, depending on how you want the data to be sorted. -
In the
Http Response
block , set theResponse Variable
field to expression as{{$block-name.val}}
.
Sample Data
5. UpdateOne
The UpdateOne
operation allows you to modify a single document. This is helpful when you need to update specific fields of a record.
- Add a UpdateOne block to your workflow. Set the
Record Id
field to{{$request.body.id}}
andUpdate Value
to{{$request.body.value}}
to specify the data that will be used to update the existing record. - In the
Http Response
block , set theResponse Variable
field to expression as{{$block-name.val}}
.
Sample Data
6. UpdateMany
The UpdateMany
operation allows you to modify multiple documents. This is helpful when you need to update specific batch of records.
- Add a UpdateMany block to your workflow. Set the
Filter Query
field to your desired query according to your data retrieval andUpdate Value
to{{$request.body}}
to specify the data that will be used to update the existing record. - In the
Http Response
block , set theResponse Variable
field to expression as{{$block-name.val}}
.
Sample Data
7. DeleteOne
The DeleteOne
operation deletes a single document based on its unique identifier. This is useful for removing individual records such as deleting a user account.
- Add a DeleteOne block to your workflow. Set the
Record Id
field to{{$request.body.id}}
so as to specify the data that will be used to create the new record. - In the
Http Response
block , set theResponse Variable
field to expression as{{$block-name.val}}
.
Sample Data
8. DeleteMany
The DeleteMany
operation deletes multiple documents based on a query. This is ideal for bulk deletions such as removing all inactive accounts.
- Add a DeleteMany block to your workflow. Set the
Delete Query
field to your desired query according to the data that will be used to delete the existing record. - In the
Http Response
block , set theResponse Variable
field to expression as{{$block-name.val}}
.
Sample Data
9. CustomQuery
The CustomQuery
operation allows for complex querying with custom filters. This is ideal for advanced data retrieval scenarios like filtering users by multiple criteria.
Reference
Check here to learn more about Zeromagic Query Operators and Property.
- Add a CustomQuery block to your workflow. Set the
Custom Aggregate Query
field to your desired query according to the data that will be used to manipulate the existing record. - In the
Http Response
block , set theResponse Variable
field to expression as{{$block-name.val}}
.
Understanding and utilizing these operations will empower you to manage your Cosmos Database effectively, whether you need to create, read, update, or delete data. Our platform simplifies these tasks, enabling you to focus on building robust applications with ease.
Explore the power of Cosmos Database operations on our platform and elevate your data management capabilities today!