Book Image

Learning Azure DocumentDB

By : Riccardo Becker
Book Image

Learning Azure DocumentDB

By: Riccardo Becker

Overview of this book

Learning DocumentDB adopts a practical, step-by-step approach to help you learn the basics of DocumentDB and use your new-found abilities in real-life scenarios and enterprise solutions. We start with the absolute basics, such as setting up a DocumentDB environment, and guide you through managing your databases, and executing simple and complex queries. Next, we explain how to work with DocumentDB using the open REST protocol, and demonstrate how JavaScript works with DocumentDB. We’ll also show you how to authenticate and execute queries. Moving on, you’ll find out how to use DocumentDB from within Node.js to kick-start your Node.js projects. Next, you’ll discover how to increase the performance of your DocumentDB database and fine-tune it. Finally, you’ll get to grips with using DocumentDB in conjunction with other services offered from the Microsoft Azure platform.
Table of Contents (15 chapters)
Learning Azure DocumentDB
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introducing indexes


As we discussed before, DocumentDB is a schema-free database containing JSON documents. By default, DocumentDB applies indexing to all document properties. This means you can specifically query for all the properties inside a document.

Explaining default indexing

Internally, DocumentDB represents all documents as trees. A dummy root node is created to make every document accessible via this root node. Every property of a document is a node in the tree representation.

The following code illustrates how one of our PersonInformation class's document is represented as a tree in JSON:

{
  "LastName": "Doe",
  "FirstName": "John",
  "DateOfBirth": {
    "Date": "1971-01-01T00:00:00",
    "Epoch": 31536000
  },
  "NumberOfHomeAutomationDevices": 1,
  "HomeAutomationDevices": [
    {
      "Manufacturer": "Contoso Inc.",
      "Type": "Heater",
      "Location": "Attic",
      "Price": 50
    }
  ],
  "Roles": [
    {
      "RoleName": "User"
    }
  ]
}

Here's the tree representation...