Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Supported Client Libraries

Supported Operations

What results can you expect?

Once the analysis/snapshot generation has completed, you can view the results in the normal manner (for example via CAST Enlighten). Some examples are shown below.

Azure Cosmos DB Database and Table Creation

...

languagec#

...

OperationMethods Supported
Create
CreateDocumentCollectionAsync


Expand
  • CreateDocumentCollectionIfNotExistsAsync
  • Insert
    • CreateDocumentAsync
    Update
    • ReplaceDocumentAsync
    • ReplaceDocumentCollectionAsync
    Select
    • ReadDocumentAsync
    • ReadDocumentCollectionAsync
    • CreateDocumentQuery
    Delete
    • DeleteDocumentAsync
    • DeleteDocumentCollectionAsync

    Objects

    ...

    Image Removed

    ...

    Image Removed

    ...

     Image Removed

    ...

     Image Removed

    ...

    Links are created for transaction and function point needs:

    ...

    Between Azure CosmosDB database object and Azure CosmosDB collection object

    ...

    • CreateDocumentCollectionAsync
    • CreateDocumentCollectionIfNotExistsAsync

    ...

    useInsertLink

    ...

    •  CreateDocumentAsync

    ...

    • ReplaceDocumentAsync
    • ReplaceDocumentCollectionAsync

    ...

    • ReadDocumentAsync
    • ReadDocumentCollectionAsync
    • CreateDocumentQuery

    ...

    • DeleteDocumentAsync
    • DeleteDocumentCollectionAsync
    titleMethods Supported for Create - 2.x
    • Microsoft.Azure.Documents.Client.DocumentClient.CreateDocumentCollectionAsync
    • Microsoft.Azure.Documents.IDocumentClient.CreateDocumentCollectionAsync
    • Microsoft.Azure.Documents.Client.DocumentClient.CreateDocumentCollectionIfNotExistsAsync
    • Microsoft.Azure.Documents.IDocumentClient.CreateDocumentCollectionIfNotExistsAsync


    Expand
    titleMethods Supported for Create - 3.x
    • Microsoft.Azure.Cosmos.Fluent.ContainerBuilder.CreateIfNotExistsAsync
    • Microsoft.Azure.Cosmos.Fluent.ContainerBuilder.CreateAsync
    • Microsoft.Azure.Cosmos.Database.CreateContainerIfNotExistsAsync
    • Microsoft.Azure.Cosmos.CosmosDatabase.CreateContainerIfNotExistsAsync
    • Microsoft.Azure.Cosmos.Database.GetContainer
    • Microsoft.Azure.CosmosDatabase.GetContainer
    • Microsoft.Azure.Cosmos.CosmosClient.GetContainer
    • Microsoft.Azure.Cosmos.Database.CreateContainerStreamAsync
    • Microsoft.Azure.CosmosDatabase.CreateContainerStreamAsync


    Expand
    titleMethods Supported for Create - CosmonautClient
    • Cosmonaut.CosmonautClient.CreateCollectionAsync 
    • Cosmonaut.ICosmonautClient.CreateCollectionAsync
    • Cosmonaut.CosmonautClient.GetCollectionAsync
    • Cosmonaut.ICosmonautClient.GetCollectionAsync


    Insert


    Expand
    titleMethods Supported for Insert - 2.x
    • Microsoft.Azure.Documents.Client.DocumentClient.CreateDocumentAsync

    • Microsoft.Azure.Documents.IDocumentClient.CreateDocumentAsync
    • Microsoft.Azure.Documents.Client.DocumentClient.UpsertDocumentAsync
    • Microsoft.Azure.Documents.IDocumentClient.UpsertDocumentAsync


    Expand
    titleMethods Supported for Insert - 3.x
    • Microsoft.Azure.Cosmos.Container.CreateItemAsync
    • Microsoft.Azure.CosmosContainer.CreateItemAsync
    • Microsoft.Azure.Cosmos.Container.CreateItemStreamAsync
    • Microsoft.Azure.CosmosContainer.CreateItemStreamAsync
    • Microsoft.Azure.Cosmos.Container.UpsertItemAsync
    • Microsoft.Azure.Cosmos.Container.UpsertItemStreamAsync


    Expand
    titleMethods Supported for Insert - CosmonautClient
    • Cosmonaut.CosmonautClient.CreateDocumentAsync
    • Cosmonaut.ICosmonautClient.CreateDocumentAsync
    • Cosmonaut.CosmonautClient.UpsertDocumentAsync
    • Cosmonaut.ICosmonautClient.UpsertDocumentAsync


    Update


    Expand
    titleMethods Supported for Update - 2.x
    • Microsoft.Azure.Documents.Client.DocumentClient.ReplaceDocumentAsync
    • Microsoft.Azure.Documents.IDocumentClient.ReplaceDocumentAsync
    • Microsoft.Azure.Documents.Client.DocumentClient.ReplaceDocumentCollectionAsync
    • Microsoft.Azure.Documents.IDocumentClient.ReplaceDocumentCollectionAsync
    • Microsoft.Azure.Documents.Client.DocumentClient.UpsertDocumentAsync
    • Microsoft.Azure.Documents.IDocumentClient.UpsertDocumentAsync


    Expand
    titleMethods Supported for Update - 3.x
    • Microsoft.Azure.Cosmos.Container.ReplaceItemAsync
    • Microsoft.Azure.Cosmos.Container.ReplaceItemStreamAsync
    • Microsoft.Azure.Cosmos.Container.ReplaceContainerAsync
    • Microsoft.Azure.CosmosContainer.ReplaceContainerStreamAsync
    • Microsoft.Azure.Cosmos.Container.ReplaceContainerStreamAsync
    • Microsoft.Azure.Cosmos.Container.UpsertItemAsync
    • Microsoft.Azure.Cosmos.Container.UpsertItemStreamAsync


    Expand
    titleMethods Supported for Update - CosmonautClient
    • Cosmonaut.CosmonautClient.UpdateDocumentAsync
    • Cosmonaut.ICosmonautClient.UpdateDocumentAsync
    • Cosmonaut.CosmonautClient.UpdateCollectionAsync
    • Cosmonaut.ICosmonautClient.UpdateCollectionAsync
    • Cosmonaut.CosmonautClient.UpsertDocumentAsync 
    • Cosmonaut.ICosmonautClient.UpsertDocumentAsync


    Select


    Expand
    titleMethods Supported for Select - 2.x
    • Microsoft.Azure.Documents.Client.DocumentClient.ReadDocumentAsync
    • Microsoft.Azure.Documents.IDocumentClient.ReadDocumentAsync
    • Microsoft.Azure.Documents.Client.DocumentClient.ReadDocumentCollectionAsync
    • Microsoft.Azure.Documents.IDocumentClient.ReadDocumentCollectionAsync
    • Microsoft.Azure.Documents.Client.DocumentClient.CreateDocumentQuery
    • Microsoft.Azure.Documents.Client.DocumentClient.CreateDocumentQuery


    Expand
    titleMethods Supported for Select - 3.x
    • Microsoft.Azure.Cosmos.Container.ReadItemAsync
    • Microsoft.Azure.CosmosContainer.ReadItemStreamAsync
    • Microsoft.Azure.Cosmos.Container.ReadItemStreamAsync
    • Microsoft.Azure.Cosmos.Container.ReadContainerStreamAsync
    • Microsoft.Azure.CosmosContainer.ReadContainerStreamAsync


    Expand
    titleMethods Supported for Select - CosmonautClient
    • Cosmonaut.CosmonautClient.GetDocumentAsync 
    • Cosmonaut.ICosmonautClient.GetDocumentAsync


    Delete


    Expand
    titleMethods Supported for Delete - 2.x
    • Microsoft.Azure.Documents.Client.DocumentClient.DeleteDocumentAsync
    • Microsoft.Azure.Documents.IDocumentClient.DeleteDocumentAsync
    • Microsoft.Azure.Documents.Client.DocumentClient.DeleteDocumentCollectionAsync
    • Microsoft.Azure.Documents.IDocumentClient.DeleteDocumentCollectionAsync


    Expand
    titleMethods Supported for Delete - 3.x
    • Microsoft.Azure.Cosmos.Container.DeleteItemAsync
    • Microsoft.Azure.CosmosContainer.DeleteItemAsync
    • Microsoft.Azure.Cosmos.Container.DeleteItemStreamAsync
    • Microsoft.Azure.Cosmos.Container.DeleteContainerAsync
    • Microsoft.Azure.CosmosContainer.DeleteContainerAsync
    • Microsoft.Azure.Cosmos.Container.DeleteContainerStreamAsync


    Expand
    titleMethods Supported for Delete - CosmonautClient
    • Cosmonaut.CosmonautClient.DeleteDocumentAsync
    • Cosmonaut.ICosmonautClient.DeleteDocumentAsync
    • Cosmonaut.CosmonautClient.DeleteCollectionAsync
    • Cosmonaut.ICosmonautClient.DeleteCollectionAsync


    Objects

    IconDescription

    Image Added

    DotNet CosmosDB Database

    Image Added

    DotNet CosmosDB Collection

     Image Added

    DotNet CosmosDB Unknown Database 

     Image Added

    DotNet CosmosDB Unknown Collection 

    Links are created for transaction and function point needs:

    Link typeWhen is this created? Methods Supported
    belongsTo

    From DotNet CosmosDB Collection object to DotNet CosmosDB Database object


    useLinkBetween the caller .NET Method objects and DotNet CosmosDB Collection object



    Expand
    titleMethods
    • CreateDocumentCollectionAsync
    • CreateDocumentCollectionIfNotExistsAsync
    • GetContainer
    • CreateContainerIfNotExistsAsync
    • CreateContainerAsync
    • CreateIfNotExistsAsync
    • CreateAsync
    • CreateContainerStreamAsync
    • CreateCollectionAsync
    • GetCollectionAsync


    useInsertLink


    Expand
    titleMethods
    • CreateDocumentAsync
    • UpsertDocumentAsync
    • CreateItemAsync
    • CreateItemStreamAsync
    • UpsertItemAsync
    • UpsertItemStreamAsync


    useUpdateLink


    Expand
    titleMethods
    • ReplaceDocumentAsync
    • ReplaceDocumentCollectionAsync
    • UpsertDocumentAsync
    • ReplaceItemAsync
    • ReplaceItemStreamAsync
    • ReplaceContainerAsync
    • ReplaceContainerStreamAsync
    • UpsertItemAsync
    • UpsertItemStreamAsync
    • UpdateDocumentAsync
    • UpdateCollectionAsync


    useSelectLink


    Expand
    titleMethods
    • ReadDocumentAsync
    • ReadDocumentCollectionAsync
    • CreateDocumentQuery
    • ReadItemAsync
    • ReadItemStreamAsync
    • ReadContainerAsync
    • ReadContainerStreamAsync
    • GetDocumentAsync


    useDeletetLink


    Expand
    titleMethods
    • DeleteDocumentAsync
    • DeleteDocumentCollectionAsync
    • DeleteItemAsync
    • DeleteContainerAsync
    • DeleteContainerStreamAsync
    • DeleteCollectionAsync


    What results can you expect?

    Once the analysis/snapshot generation has completed, you can view the results in the normal manner (for example via CAST Enlighten). Some examples are shown below.

    Azure Cosmos DB Database and Table Creation

    Expand
    titleDB and Table Creation


    Code Block
    languagec#
    titleCreateDatabase and CreateCollection - 2.x
    private static readonly string databaseName = "samples";
    private static readonly string collectionName = "document-samples";
    
    private static async Task Initialize()
            {
                await client.CreateDatabaseIfNotExistsAsync(new Database { Id = databaseName });
    
                // We create a partitioned collection here which needs a partition key. Partitioned collections
                // can be created with very high values of provisioned throughput (up to OfferThroughput = 250,000)
                // and used to store up to 250 GB of data. You can also skip specifying a partition key to create
                // single partition collections that store up to 10 GB of data.
                DocumentCollection collectionDefinition = new DocumentCollection();
                collectionDefinition.Id = collectionName;
    
                // For this demo, we create a collection to store SalesOrders. We set the partition key to the account
                // number so that we can retrieve all sales orders for an account efficiently from a single partition,
                // and perform transactions across multiple sales order for a single account number. 
                collectionDefinition.PartitionKey.Paths.Add("/AccountNumber");
    
                // Use the recommended indexing policy which supports range queries/sorting on strings
                collectionDefinition.IndexingPolicy = new IndexingPolicy(new RangeIndex(DataType.String) { Precision = -1 });
    
                // Create with a throughput of 1000 RU/s
                await client.CreateDocumentCollectionIfNotExistsAsync(
                    UriFactory.CreateDatabaseUri(databaseName),
                    collectionDefinition,
                    new RequestOptions { OfferThroughput = 1000 });
            }
    
    


    Image Added

    Code Block
    languagec#
    titleCreate Database and Container - 3.x
    private static async Task Initialize(CosmosClient client)
            {
                database = await client.CreateDatabaseIfNotExistsAsync(databaseId);
    
                ContainerProperties containerProperties = new ContainerProperties(containerId, partitionKeyPath: "/AccountNumber");
    
                // Create with a throughput of 1000 RU/s
                container = await database.CreateContainerIfNotExistsAsync(
                    containerProperties,
                    throughput: 1000);
            }


    Image Added

    Insert Operation

    Expand
    titleInsert Operation


    Code Block
    languagec#
    titleCreateDocumentAsync - 2.x
    private static async Task CreateDocumentsAsync()
            {
                Uri collectionUri = UriFactory.CreateDocumentCollectionUri(databaseName, collectionName);
                Console.WriteLine("\n1.1 - Creating documents");
                SalesOrder salesOrder = GetSalesOrderSample("SalesOrder1");
                await client.CreateDocumentAsync(collectionUri, salesOrder);
    			SalesOrder2 newSalesOrder = GetSalesOrderV2Sample("SalesOrder2");
                await client.CreateDocumentAsync(collectionUri, newSalesOrder);
    		}

    Image Added



    Code Block
    languagec#
    titleCreateItemAsync - 3.x
    private static async Task<SalesOrder> CreateItemsAsync()
            {
                Console.WriteLine("\n1.1 - Creating items");
    
                // Create a SalesOrder object. This object has nested properties and various types including numbers, DateTimes and strings.
                // This can be saved as JSON as is without converting into rows/columns.
                SalesOrder salesOrder = GetSalesOrderSample("SalesOrder1");
                ItemResponse<SalesOrder> response = await container.CreateItemAsync(salesOrder, new PartitionKey(salesOrder.AccountNumber));
                SalesOrder salesOrder1 = response;
                Console.WriteLine($"\n1.1.1 - Item created {salesOrder1.Id}");
    		}


    Image Added


    Code Block
    languagec#
    titleCreateDocumentAsync - CosmonautClient
    public async Task<DocumentStorageResponse<TEntity>> InsertAsync<TEntity>(TEntity entity, DocumentOptions options = null, CancellationToken cancellationToken = default)
            where TEntity : Entity
            {
                var response = await this.documentClient.CreateDocumentAsync(this.databaseName, this.collectionName, entity, options.ToRequestOptions(),     cancellationToken).ConfigureAwait(false);
                return response.ToDocumentStorageResponse();
            }
    

    Image Added

    Select Operation

    Expand
    titleSelect Operation


    Code Block
    languagec#
    titleReadDocumentAsync - 2.x
    private static async Task ReadDocumentAsync()
            {
                Console.WriteLine("\n1.2 - Reading Document by Id");
    
                var response = await client.ReadDocumentAsync(
                	UriFactory.CreateDocumentUri(databaseName, collectionName, "SalesOrder1"), 
                    new RequestOptions { PartitionKey = new PartitionKey("Account1") });
    		}

    Image Added

    Code Block
    languagec#
    titleReadDocumentCollectionAsync - 2.x
    private static async Task ReadDocumentCollectionAsync()
            {
                Console.WriteLine("\n1.7 - Reading a document");
                ResourceResponse<Document> response = await client.ReadDocumentCollectionAsync(
                    UriFactory.CreateDocumentUri(databaseName, collectionName, "SalesOrder3"),
                    new RequestOptions { PartitionKey = new PartitionKey("Account1") });
            }

    Image Added

    Code Block
    languagec#
    titleCreateDocumentAsync - 2.x
    private static SalesOrder QueryDocuments()
            {
                Console.WriteLine("\n1.4 - Querying for a document using its AccountNumber property");
    
                SalesOrder querySalesOrder = client.CreateDocumentQuery<SalesOrder>(
                    UriFactory.CreateDocumentCollectionUri(databaseName, collectionName))
                    .Where(so => so.AccountNumber == "Account1")
                    .AsEnumerable()
                    .First();
    
                Console.WriteLine(querySalesOrder.AccountNumber);
                return querySalesOrder;
            }

    Image Added


    Code Block
    languagec#
    titleReadItemAsync - 3.x
    private static async Task ReadItemAsync()
            {
                Console.WriteLine("\n1.2 - Reading Item by Id");
    
                // Note that Reads require a partition key to be specified.
                ItemResponse<SalesOrder> response = await container.ReadItemAsync<SalesOrder>(
                    partitionKey: new PartitionKey("Account1"),
                    id: "SalesOrder1");
    		}


    Image Added


    Code Block
    languagec#
    titleGetDocumentAsync - CosmonautClient
    public Task<TEntity> FindAsync<TEntity>(string id, DocumentOptions options = null, CancellationToken cancellationToken = default)
                where TEntity : Entity
            {
                return this.documentClient.GetDocumentAsync<TEntity>(this.databaseName, this.collectionName, id, options.ToRequestOptions(), cancellationToken);
            }

    Image Added

    Update Operation

    Expand
    titleUpdate Operation


    Code Block
    languagec#
    titleReplaceDocumentAsync - 2.x
    	private static async Task ReplaceDocumentAsync(SalesOrder order)
            {
                Console.WriteLine("\n1.5 - Replacing a document using its Id");
                order.ShippedDate = DateTime.UtcNow;
                ResourceResponse<Document> response = await client.ReplaceDocumentAsync(
                    UriFactory.CreateDocumentUri(databaseName, collectionName, order.Id), 
                    order);
    
                var updated = response.Resource;
                Console.WriteLine("Request charge of replace operation: {0}", response.RequestCharge);
                Console.WriteLine("Shipped date of updated document: {0}", updated.GetPropertyValue<DateTime>("ShippedDate"));
            }

    Image Added

    Code Block
    languagec#
    titleReplaceCollectionDocumentAsync - 2.x
    private static async Task ReplaceDocumentCollectionAsync()
            {
                Console.WriteLine("\n1.7 - Updating a document");
                ResourceResponse<Document> response = await client.ReplaceDocumentCollectionAsync(
                    UriFactory.CreateDocumentUri(databaseName, collectionName, "SalesOrder3"),
                    new RequestOptions { PartitionKey = new PartitionKey("Account1") });
    
                Console.WriteLine("Request charge of update operation: {0}", response.RequestCharge);
                Console.WriteLine("StatusCode of operation: {0}", response.StatusCode);
            }

    Image Added


    Code Block
    languagec#
    titleReplaceItemAsync - 3.x
    private static async Task ReplaceItemAsync(SalesOrder order)
            {
                Console.WriteLine("\n1.6 - Replacing a item using its Id");
    
                order.ShippedDate = DateTime.UtcNow;
                ItemResponse<SalesOrder> response = await container.ReplaceItemAsync(
                    partitionKey: new PartitionKey(order.AccountNumber),
                    id: order.Id,
                    item: order);
    		}

    Image Added


    Code Block
    languagec#
    titleUpdateDocumentAsync - CosmonautClient
    public async Task<DocumentStorageResponse<TEntity>> UpdateAsync<TEntity>(TEntity entity, DocumentOptions options = null, CancellationToken cancellationToken = default)
                where TEntity : Entity
            {
                var requestOptions = options.ToRequestOptions();
                var document = entity.ToCosmonautDocument(this.settings.JsonSerializerSettings);
                var response = await this.documentClient.UpdateDocumentAsync(this.databaseName, this.collectionName, document, requestOptions, cancellationToken)              .ExecuteCosmosCommand(entity).ConfigureAwait(false);
                return response.ToDocumentStorageResponse();
            }

    Image Added

    Upsert Operation

    Expand
    titleUpsert Operation


    Code Block
    languagec#
    titleUpsertDocumentAsync - 2.x
    private static async Task UpsertDocumentAsync()
            {
                Console.WriteLine("\n1.6 - Upserting a document");
    
                var upsertOrder = GetSalesOrderSample("SalesOrder3");
                ResourceResponse<Document> response = await client.UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), upsertOrder);
                var upserted = response.Resource;
    
                Console.WriteLine("Request charge of upsert operation: {0}", response.RequestCharge);
                Console.WriteLine("StatusCode of this operation: {0}", response.StatusCode);
                Console.WriteLine("Id of upserted document: {0}", upserted.Id);
                Console.WriteLine("AccountNumber of upserted document: {0}", upserted.GetPropertyValue<string>("AccountNumber"));
    
                upserted.SetPropertyValue("AccountNumber", "updated account number");
                response = await client.UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), upserted);
                upserted = response.Resource;
    
                Console.WriteLine("Request charge of upsert operation: {0}", response.RequestCharge);
                Console.WriteLine("StatusCode of this operation: {0}", response.StatusCode);
                Console.WriteLine("Id of upserted document: {0}", upserted.Id);
                Console.WriteLine("AccountNumber of upserted document: {0}", upserted.GetPropertyValue<string>("AccountNumber"));
            }

    Image Added


    Code Block
    languagec#
    titleUpsertItemAsync - 3.x
    private static async Task UpsertItemAsync()
            {
                Console.WriteLine("\n1.8 - Upserting a item");
    
                SalesOrder upsertOrder = GetSalesOrderSample("SalesOrder3");
                
                //creates the initial SalesOrder document. 
                //notice the response.StatusCode returned indicates a Create operation was performed
                ItemResponse<SalesOrder> response = await container.UpsertItemAsync(
                    partitionKey: new PartitionKey(upsertOrder.AccountNumber),
                    item: upsertOrder);
    		}

    Image Added

    Code Block
    languagec#
    titleUpsertDocumentAsync - CosmonautClient
    public async Task<DocumentStorageResponse<TEntity>> UpsertAsync<TEntity>(TEntity entity, DocumentOptions options = null, CancellationToken cancellationToken = default)
            where TEntity : Entity
            {
                  var requestOptions = options.ToRequestOptions();
                  var document = entity.ToCosmonautDocument(this.settings.JsonSerializerSettings);
                  var response = await this.documentClient.UpsertDocumentAsync(this.databaseName, this.collectionName, document, requestOptions, cancellationToken).ExecuteCosmosCommand(entity).ConfigureAwait(false);
                  return response.ToDocumentStorageResponse();
            }
    



    Image Added

    Delete Operation

    Expand
    titleDelete Operation


    Code Block
    languagec#
    titleDeleteDocumentAsync - 2.x
     private static async Task DeleteDocumentAsync()
            {
             
    Database
     
    db2
     
    =
     
    this.client.CreateDatabaseIfNotExistsAsync(new Database { Id = "FamilyDatabase2" }).Result;
    Console.WriteLine("\n1.7 - Deleting a document");
           
    }
         ResourceResponse<Document> response = await 
    private
    client.DeleteDocumentAsync(
    
    async
     
    Task
     
    CreateCollection()
             
    {
         UriFactory.CreateDocumentUri(databaseName, collectionName, "SalesOrder3"),
         
    //Creating
     
    DocumentCollection
     
    using
     
    UriFactory
            new RequestOptions { PartitionKey = 
    await this.client.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri
    new PartitionKey("
    FamilyDatabase
    Account1")
    , new DocumentCollection {Id =
     });
    
                
    "FamilyCollection"}
    Console.WriteLine("Request charge of delete operation: {0}", response.RequestCharge);
                
    // Creating Document Collection using string Link
    Console.WriteLine("StatusCode of operation: {0}", response.StatusCode);
            }

    Image Added

    Code Block
    languagec#
    titleDeleteDocumentCollectionAsync - 2.x
    private static async Task DeleteDocumentCollectionAsync()
        
    await
     
    this.client.CreateDocumentCollectionIfNotExistsAsync("dbs/FamilyDatabase",
     
    new
     
    DocumentCollection
     {
    Id
    
    
    =
     
    "FamilyCollection2"});
               Console.WriteLine("\n1.7 - 
    //
    Deleting 
    Creating DatabaseUri
    a document");
                
    var
    ResourceResponse<Document> 
    databaseUri
    response = await 
    UriFactory
    client.
    CreateDatabaseUri("FamilyDatabase2");
    DeleteDocumentCollectionAsync(
                    
    this
    UriFactory.
    client.CreateDocumentCollectionIfNotExistsAsync(databaseUri, new DocumentCollection {Id = "FamilyCollectionNewWay"});
    CreateDocumentUri(databaseName, collectionName, "SalesOrder3"),
                    new RequestOptions { 
    } }

    Image Removed

    Insert Operation

    Code Block
    languagec#
    titlePutItem
    private async InsertDocument(Family family){
    PartitionKey = new PartitionKey("Account1") });
    
               
    await
     
    this
    Console.
    client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collName), family); }

    Image Removed

    Select Operation

    Code Block
    languagec#
    titleReadDocumentAsync
    private async Task ReadDocument(Family family){
    WriteLine("Request charge of delete operation: {0}", response.RequestCharge);
                
    await this.client.ReadDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collName, family.Id)); }

    ...

    ReadDocumentCollectionAsync
    Console.WriteLine("StatusCode of operation: {0}", response.StatusCode);
            }


    Image Added


    Code Block
    languagec#
    title
    DeleteItemAsync - 3.x
    private static async Task 
    ReadCollection() {
    DeleteItemAsync()
            {
                Console.WriteLine("\n1.9 - Deleting 
    // Using UriFactory object
    a item");
                ItemResponse<SalesOrder> response = await 
    this
    container.
    client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collName));
    DeleteItemAsync<SalesOrder>(
                    partitionKey: 
    //Using stringLink
    new PartitionKey("Account1"),
                    
    await this.client.ReadDocumentCollectionAsync("dbs/FamilyDatabase/colls/FamilyCollection2
    id: "SalesOrder3");
    
              
    //Creating
     
    DocumentCollectionUri
     Console.WriteLine("Request charge of delete operation: {0}", response.RequestCharge);
         
    var
         
    collLink
     
    =
     
    UriFactory
    Console.
    CreateDocumentCollectionUri
    WriteLine("
    FamilyDatabase2
    StatusCode of operation: {0}", 
    "FamilyCollectionNewWay"
    response.StatusCode);
    
            
    await this.client.ReadDocumentCollectionAsync(collLink);
    }

    ...


    Image Added


    Code Block
    languagec#
    title
    CreateDocumentQuery
    private async Task QueryData()
    {
    	FeedOptions queryOptions = new FeedOptions { MaxItemCount = -1 };
    	IQueryable<Family> familyQuery = this.client.CreateDocumentQuery<Family>(
    				  		 UriFactory.CreateDocumentCollectionUri(databaseName, collName), queryOptions)	
    					        .Where(f => f.LastName == "Andersen");
    }

    Image Removed

    Update Operation

    Code Block
    languagec#
    titleReplaceDocumentAsync
    private async Task ReplaceDocument(Family updatedFamily)
    {            
    	await this.client.ReplaceDocumentAsync("dbs/FamilyDatabase/colls/FamilyCollection/docs/familyName", updatedFamily);
    }		

    Image Removed

    Code Block
    languagec#
    titleReplaceDocumentCollectionAsync
    private async Task ReplaceCollection(DocumentCollection updatedColl1, DocumentCollection updatedColl2)
    {            
              await this.client.ReplaceDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collName), updatedColl1);
              // Creating DocumentCollectionUri
              var collectionLink = UriFactory.CreateDocumentCollectionUri("FamilyDatabase2", "FamilyCollectionNewWay");
              await this.client.ReplaceDocumentCollectionAsync(collectionLink, updatedColl2);
    }

    Image Removed

    Delete Operation

    Code Block
    languagec#
    titleDeleteDocumentAsync
    private async Task DeleteDocument(string documentName)
    {
                await this.client.DeleteDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collName, documentName));
                Console.WriteLine("Deleted Family {0}", documentName);
    }

    Image Removed

    Code Block
    languagec#
    titleDeleteDocumentCollectionAsync
    private async Task DeleteCollection()
    {
                await this.client.DeleteDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collName));
                await this.client.DeleteDocumentCollectionAsync("dbs/FamilyDatabase/colls/FamilyCollection2");
    }

    Image Removed

    Evolution

    • Previously, only  files consisting of relevant Azure CosmosDB imports were processed further for analysing.
    • Support has been evolved to process a  file when it does not contain Azure CosmosDB import but makes use of its methods (APIs). Assumption here is file makes use of same namespace as used in the file containing Azure CosmosDB imports.

    Limitations

    • Database and collection names are resolved as known objects only in the following situations:
      • Name is hardcoded
      • Name is defined in the variable in the local method
      • Name is defined as C# field
      • Name is provided in the App.config file
      • Database object is used while creating the database
      • DocumentCollection object is used while creating the collection

    Future development

    ...

    DeleteDocumentAsync - CosmonautClient
    public async Task<DocumentStorageResponse<TEntity>> RemoveAsync<TEntity>(string id, DocumentOptions options = null, CancellationToken cancellationToken = default)
                 where TEntity : Entity
                 {
                        var response = await this.documentClient.DeleteDocumentAsync(this.databaseName, this.collectionName, id, options.ToRequestOptions(), cancellationToken)
    .ExecuteCosmosCommand<TEntity>(null).ConfigureAwait(false);
                        return response.ToDocumentStorageResponse();
                 }
    


    Image Added


    Reading App.config

    Expand
    titleApp.config


    Code Block
    languagec#
    titleCreateDocumentAsync - 2.x
    private static readonly string collectionName = ConfigurationManager.AppSettings["CollectionName"];
    private static readonly string database = ConfigurationManager.AppSettings["DatabaseName"];
    private static void InsertDataWithDatabaseAndCollectionArgument(Family family)
    {
    	await this.client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(database, collectionName), family);
    
    }


    Code Block
    languagexml
    titleApp.config
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <startup>
    	<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
    <appSettings>
    	<add key="EndPointUrl" value="https://localhost:443/" />
    	<add key="AuthorizationKey" value="C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" />
    	<add key="DatabaseName" value="bulkUpdateDb" />
    	<add key="CollectionName" value="bulkUpdateColl" />
    	<add key="CollectionThroughput" value="100000" />
    	<add key="ShouldCleanupOnStart" value="false" />
    	<add key="ShouldCleanupOnFinish" value="false" />
    	<add key="NumberOfDocumentsToUpdate" value="2500000" />
    	<add key="NumberOfBatches" value="25" />
    	<add key="CollectionPartitionKey" value="/profileid" />
    </appSettings>
    


    Image Added

    Evolution

    • Support for CosmosDB 3.x
    • Better resolution of Database and Collection names
    • Provided support to additional APIs
    • Reading Database and Collection values from App.config
    • Support for CosmonautClient

    Limitations

    • Unknown database and collection objects are created when unable to resolve Database and Collection