Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Azure DocumentDB

You're reading from   Learning Azure DocumentDB Create outstanding enterprise solutions around DocumentDB using the latest technologies and programming tools with Azure

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher
ISBN-13 9781783552467
Length 152 pages
Edition 1st Edition
Concepts
Arrow right icon
Author (1):
Arrow left icon
Riccardo Becker Riccardo Becker
Author Profile Icon Riccardo Becker
Riccardo Becker
Arrow right icon
View More author details
Toc

Creating resources

As we have seen before, entities inside DocumentDB are called resources. The way resources are managed is a uniform process, and this makes understanding these CRUD operations easier. This section will discuss how to create resources inside your database.

Creating a collection

Before you can create and update documents, you first need to have a collection available. In Chapter 1, Getting Started with DocumentDB, we saw how a collection can be created straight from the Azure portal. In this section, we are going to create one by using the .NET SDK using Visual Studio 2013 and C#.

The following code snippet shows how you can check if a collection already exists; it also demonstrates how a collection can be created:

//prerequisite before we can work. We need a DocumentClient and a Database.
    DocumentClient client = new DocumentClient(new Uri(docDBUri), key);
    Database database = client.CreateDatabaseQuery().Where(d => d.Id == "devicehub").AsEnumerable().First...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image