Skip to main content

Querying CosmosDB. Part 3

Hi guys !!!

We continue with "Querying CosmosDB" series. You can read previous parts in Part1 and Part 2.

Now we added event notes to some documents. It's means some speakers added short notes or tags to theirs events. You can download a new version of our JSON Example (JSON Example 2)

Show me please !!



Ok. Fine !! Retrieve a list of all events with notes.
Query

SELECT c.event_name, c.speaker, c.event_notes FROM c
where IS_DEFINED(c.event_notes)

Results


I don't want all notes, just with 'pool' word.

Query

SELECT c.speaker, c.event_name, c.event_notes FROM c
JOIN notes IN c.event_notes
where IS_DEFINED(c.event_notes) AND CONTAINS(notes,"pool")

Results



I don't care about event name or speakers. Let me list just notes!!!

Query

SELECT notes FROM c
JOIN notes IN c.event_notes


Results


Please just a list, not object list!!!

Query

SELECT VALUE notes FROM c
JOIN notes IN c.event_notes

Results



Bye !!!! 

To be Continue.......

Comments

Popular posts from this blog

Inserting Data with Azure Functions in CosmosDB

I was wondering how to use Azure Function to insert data in CosmosDB when this function receives an HTTP request
Surprise!!  It´s easy 
Step 1. Create your DataBase and Collection inside CosmosDB in Azure. 

Step 2. Create Function App



Step 3.  Create a new function. In this case use template "HttpTrigger - C#"


Step 4. Select "Integrate" option 

Be sure to change option in "Allowed HTTP methods" and select only "POST" HTTP method. 

Step 5. Create output binding


Step 6.  Configuring output binding

a:  Name of the entity variable to insert in CosmosDB. b:  Name of the collection where the entity will be inserted (see image in Step 1). c:  Partition Key  in case you need to define it.  d:  DataBase name in Cosmos DB (see image in Step 1). e:  ConnectionString.

Step 7.   "Short" programming....
a: Entity variable referenced in Step 6. a b: Entity type (custom class). 
outputDocument= req.Content.ReadAsAsync<DTODocument>().Result;
The functio…

Update data in COSMOS DB with Azure Functions.

I was looking for a way to update COSMOS DB document after receive a  request inside Azure Function without any COSMOS DB biding.

I didn't find a way !!
 I took another way. I don't know if it is the right or wrong way. But this way works for me.

Scenario is very simple. We have sales orders arriving into the data base. We have another Azure function to insert those new orders. But suppose we need to cancel some order. How to do that using Azure Function ?

Let´s start !!!
Step 1. Sample Collection. This collection is very simple,  we are focused on results.


Step 2. Create a Function and Select HttpTrigger template. 


Step 3. Code 


More code. 

Step 4. Test

Step 5. Results 




See you soon 

Add more security to an Azure CosmosDB Account.

W e can access programmatically to Azure Cosmos DB resources to create, query, and delete databases, document collections, and documents via REST API. To perform operations on Azure Cosmos DB resources, you can send HTTPS requests with a selected method: GET, POST, PUT, or DELETE to an CosmosDB endpoint. 
Frequently we build architecture with centralized access to a persistence layer, then we won't let other applications access directly to this layer.

Suppose we have the following hypothetical scenario (see Figure 1):


Only WEB API Service with IP1 is allowed to establish connections with CosmosDB EndPoint. The others elements showed as Application are not allowed. By default we have in our CosmosDB resource the following configuration (see Figure 2) in Firewall and Virtual Networks option.


To show you how this feature works, we are going to create a WEP API with a single function (route) to retrieve some information from a CosmosDB collection. We won't create web application, …