DocumentDB,
as a NoSQL store, is truly schema-free. It allows you to store and query any
JSON document, regardless of schema. The service provides built-in automatic
indexing support – which means you can write JSON documents to the store and
immediately query them using a familiar document oriented SQL query
grammar. DocumentDB is designed to linearly scale to meet the needs of an
application.
In this article,
we learn how to perform CRUD operations on DocumentDb via Logic Apps.
For the
creation of DocumentDb, we first need to create a DocumentDb account.
Ø ID: Name of the DocumentDb account.
Ø Resource Group: Either create new
resource group or use existing.
Ø Location: Choose the Microsoft data
center you want this account to be hosted.
Once you
click on create, the DocumentDb account will be created.
Next step is
to add database in DocumentDb, for which you will have to open the DocumentDb
account you have created. Goto Browse and Add Database.
Ø ID: Name of the DocumentDb database
Next step is
to add collection in the database of the DocumentDb, for which you will have to
open the DocumentDb account you have created. Goto Browse and Add Collection.
Ø Collection Id:
Name of the DocumentDb collection.
Ø Storage Capacity: By default, Storage Capacity is set to 250 GB to
handle partitioned collections.
Ø Partition Key:
enter a partition key for the collection. This is required for partitioned
collections and optional for single partition collections.
Ø Database: either
create a new database or use an existing one.
Create a new
logic app. This logic app will be used to Insert and Update documents in
documentdb.
Request: This trigger serves as an endpoint
that you call via an HTTP Request to invoke your logic app.
Ø HTTP POST to this URL: This URL will be created automatically once you save the logic app and
it will be used as an endpoint by the REST client to invoke this logic app.
Ø Request Body JSON Schema: This is an optional property, which validates the incoming
request. Useful for helping subsequent workflow steps know which properties to
reference.
1) Create and Update Document
This action
can be used under DocumentDb activity for inserting new documents and updating
the existing document.
Ø Database ID:
Specify the database where the document should be created or updated.
Ø Collection ID:
Specify the collection where the document should be created or updated.
Ø Document: The
document, which needs to be inserted, in our case it will be the body of the
request made by the REST client.
Ø IsUpsert: If
set to true, the document will be replaced if it exists else created.
2) Send an email
This action
can be used under Outlook 365 connector, to trigger an email.
Ø Body: Body of
the message.
Ø Subject:
Subject of the message.
Ø To: The email
addresses of the recipients.
The logic
apps run was successful and the document was inserted in the collection
specified.
We received
a mail in the specified email address as well with message body.
Upon
checking, the collection we could see that the document has be successfully
created in the collection specified.
Similarly,
same document was successfully updated in documentdB in the next hit.
Upon
checking, the collection we could see that the document has be successfully updated
in the collection specified.
Create a new
logic app. This logic app will be used to read documents from documentdb.
Request: This
trigger serves as an endpoint that you call via an HTTP Request to invoke your
logic app.
1) HTTP POST to this URL: This URL will be created automatically once you save the logic app and
it will be used as an endpoint by the REST client to invoke this logic app.
2) Request Body JSON Schema: This is an optional property, which validates the incoming
request. Useful for helping subsequent workflow steps know which properties to
reference.
1) Get Document
This action
can be used under DocumentDb connector for fetching the documents from the
DocumentDb.
Ø Database ID:
Specify the database where the document should be created or updated.
Ø Collection ID:
Specify the collection where the document should be created or updated.
Ø Document ID:
The ID of the document, which needs to fetched from the documentDb.
2) Response
This action
type contains the entire response payload from an HTTP request and includes a
statusCode, body, and headers:
Ø Status Code:
The HTTP status code
Ø Headers: A
JSON object of any response headers to include
Ø Body: The
response body
The logic
apps run was successful and it was able to fetch the document with the document
id ‘abc3’ from the documentDb.
The response
was displayed back on the Boomerang.
Create a new
logic app. This logic app will be used to delete documents from documentdb.
Request: This
trigger serves as an endpoint that you call via an HTTP Request to invoke your
logic app.
1) HTTP POST to this URL: This URL will be created automatically once you save the logic app and
it will be used as an endpoint by the REST client to invoke this logic app.
2) Request Body JSON Schema: This is an optional property, which validates the incoming
request. Useful for helping subsequent workflow steps know which properties to
reference.
1) Delete a Document
This action
can be used under DocumentDb connector for deleting the documents from the
DocumentDb.
Ø Database ID:
Specify the database where the document should be created or updated.
Ø Collection ID:
Specify the collection where the document should be created or updated.
Ø Document ID:
The ID of the document, which needs to deleted from the documentDb.
3) Response
This action
type contains the entire response payload from an HTTP request and includes a
statusCode, body, and headers:
Ø Status Code:
The HTTP status code
Ø Headers: A
JSON object of any response headers to include
Ø Body: The
response body
The logic
apps run was successful and it was able to delete the document with the
document id ‘abc2’ from the documentDb.
The response
was displayed back on the Boomerang.
Moreover, the
document was not visible anymore in the collection.