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

Using resource tokens


Resource tokens are tokens associated with permission resources and establish connections between a user and the permissions of that user for resources stored in DocumentDB (collections, documents, and stored procedures).

Creating resource tokens

Imagine a scenario where a multi-tenant web application needs access to your database. For each tenant, a separate collection inside the database is created. The web application only needs access to the specific collection for the tenant. We can solve this by creating a resource token only for the new collection.

The following steps are performed to achieve this goal:

  1. Create a tenant-specific collection.

  2. Create a resource token for that collection.

  3. Have the web application use the resource token to gain access to the collection.

Creating a collection

The following C# code snippet creates a collection for a tenant called Contoso:

  // Check if collection already exists
  DocumentCollection tenantCollection =
  client.CreateDocumentCollectionQuery...