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 transactions


Transactions inside DocumentDB are applicable only in server-side code. This means that building a transactional system can be achieved, for example, by writing stored procedures. Since stored procedures exist on a collection level, transactions can only span one collection, and adding or modifying documents across collections is not supported at the time of writing.

DocumentDB handles all logic that is running inside a stored procedure or trigger a transaction explicitly. There is no need to start and commit a transaction whatsoever. This is explicitly managed by the execution engine of DocumentDB. If an exception is raised inside the stored procedure or trigger, the entire transaction is aborted accordingly. This prevents inconsistent data by default. A simple example of a transaction in a stored procedure is shown in the following snippet:

function TransactionExample(document) {
  var collection = getContext().getCollection();
  var collectionLink = collection.getSelfLink...