To perform query operations, we need to add in some data. You can add as many documents as you want but, for the sake of example, I am going to add two nested JSON documents.
The first document is shown in the following code:
{ "id": "100", "lastName": "Doe", "parents": [ { "firstName": "John" }, { "firstName": "Mary"} ], "children": [ { "firstName": "Emily", "gender": "female", "grade": 5, "pets": [{ "givenName": "Fluffy" }] } ], "address": { "state": "WA", "county": "King", "city": "seattle" }, "creationDate": 1431620472, "isRegistered": true }
Here is the second document, with a few more changes:
{
"id": "200",
"parents": [
{ "familyName": "Wakefield", "givenName": "Robin" },
{ "familyName": "Miller", "givenName": "Ben" }
],
"children": [
{
"familyName": "Merriam",
"givenName": "Jesse",
"gender": "female", "grade": 1,
"pets": [
{ "givenName": "Goofy" },
{ "givenName": "Shadow" }
]
},
{
"familyName": "Miller",
"givenName": "Lisa",
"gender": "female",
"grade": 8 }
],
"address": { "state": "NY", "county": "Manhattan", "city": "NY" },
"creationDate": 1431620462,
"isRegistered": false
}
To create these documents using Azure portal, perform these steps.
- Log in to your Azure portal and click on the Azure Cosmos DB option on the left side of the option bar.
- Go to Data Explorer from the left menu and select the collection we created in the last chapter.
- Click on the New Document button and add the JSON mentioned above.
Once the documents are created, we can query them.