Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey, connectionPolicy))
- {
- //this is where the magic is happening.
- //define a collection of UniqueKeys, which are in themselves a collection of Paths.
- var uniqueKeyPolicy = new UniqueKeyPolicy {UniqueKeys = new Collection<UniqueKey>{ new UniqueKey { Paths = new Collection<string> { "/name" } } }};
- var db = await client.CreateDatabaseIfNotExistsAsync(new Database { Id = DatabaseName });
- var coll = await client.CreateDocumentCollectionIfNotExistsAsync(
- UriFactory.CreateDatabaseUri(DatabaseName),
- new DocumentCollection { Id = CollectionName, UniqueKeyPolicy = uniqueKeyPolicy }
- );
- Console.WriteLine("\n1.1. Created Collection \n{0}", coll);
- var doc1 = await client.CreateDocumentAsync(
- UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName), new { name = "Ryan" }
- );
- Console.WriteLine("\n1.1. Doc1 Created\n{0}", doc1);
- var doc2 = await client.CreateDocumentAsync(
- UriFactory.CreateDocumentCollectionUri(DatabaseName, CollectionName), new { name = "Ryan" }
- );
- Console.WriteLine("\n1.1. Doc2 Created\n{0}", doc2);
- }
Add Comment
Please, Sign In to add comment