IT:AD:Azure:REsources:Microsoft:DocumentDB

* Highly Scalable, Tunable, Fully Managed Service. * Differs from traditional relational databases in that it is a Schema-less/Constraints-less document object db.

  • A document is a object containing n variables.

* Documents are serialized and returned using IT:AD:JSON * All fields of an object are indexed as saved, making it very efficient to find records later. * Documents objects can be queried for using a form of IT:AD:SQL. * A Susbcription can have n Accounts, each which can have *n databases, each with n collections.

  • Note: Pricing is determined based on the number of collections in an account.
    • S0=25…(tbc)
    • S1=250 requests/sec.
    • S2=1000 rps.

* Coding:

  • Prerequisites:
    • Nuget packages:Microsoft.Azure.DocumentDB
    • An Account's
    • Endpoint (eg: foobar.documents.azure.com) and Authorization Key (eg: BNey...etc...)

// Create an Account client:
var documentDbClient = new DocumentClient(new Uri(EndpointUrl), AuthorizationKey);
// Optionally create a new Database:
var databaseDefinition = new Database { Id = "mynewdb" }; 
var result = await client.CreateDatabaseAsync(databaseDefinition); 
var database = result.Resource;
Console.WriteLine(" Database Id: {0}; Rid: {1}", database.Id, database.ResourceId); 
// eg: Output would be "Database Id: mynewdb; Rid: ltpJAA=="
// Retrieve a list of all databases by invoking CreateDatabaseQuery without arguments.
//  var databases = client.CreateDatabaseQuery().ForEach(x=> Console.WriteLine(" Database Id: {0}; Rid: {1}", x.Id, x.ResourceId));

// Crete a Collection
var collectionDefinition = new DocumentCollection { Id = "Bar" };
var options = new RequestOptions { OfferType = offerType };
var result = await client.CreateDocumentCollectionAsync(database.SelfLink, collectionDefinition, options);
var collection = result.Resource;

// Create a document

   dynamic document1Definition = new {
      name = "New Customer 1", address = new {
         addressType = "Main Office", 
         addressLine1 = "123 Main Street", 
         location = new {
            city = "Brooklyn", stateProvinceName = "New York" 
         }, postalCode = "11229", countryRegionName = "United States"
      }, 
   };
	
   Document document1 = await CreateDocument(client, document1Definition); 


//Drop a collection
//   await client.DeleteDocumentCollectionAsync(collection.SelfLink);

//Delete a database
Database database = client.CreateDatabaseQuery("SELECT * FROM c WHERE c.id = 'tempdb1'").AsEnumerable().First();
await client.DeleteDatabaseAsync(database.SelfLink);

  • /home/skysigal/public_html/data/pages/it/ad/azure/resources/microsoft/documentdb/home.txt
  • Last modified: 2023/11/04 02:45
  • by 127.0.0.1