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

Updating documents


After executing some basic SELECT queries against our collection, it is time to do some updating. This means looking up the document, changing information, and saving it to the collection. Consider the following C# code snippet:

Updating documents

In the following code snippets, we will update a document, set a new date of birth, and save the document to the collection.

Note

To enable faster processing, we store the DateTime fields as epoch values so that range queries are executed efficiently.

I used information from the official Azure blogs (http://azure.microsoft.com/blog/2014/11/19/working-with-dates-in-azure-documentdb-4/) to create the following code snippet. Instead of comparing dates, the corresponding epoch values are compared inside the query. First, a document is retrieved from the collection using a filter on the first and last name. A new date of birth value is created and written back to the collection. The code is as follows:

var documentByLinq = (from c in client...