Page tree

Versions Compared

Key

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

...

Supported Client Libraries

MongoDB Mongodb.Net Driver dotnet driver 2.x

Supported Operations

Operation

Methods Supported

Create
  • CreateCollection
  • CreateCollectionAsync
  • GetCollection

    Insert
    • MongoDB.Driver.IMongoCollection.InsertOne
    • MongoDB.Driver.IMongoCollection.InsertOneAsync
    • MongoDB.Driver.IMongoCollection.InsertManyAsync
    • MongoDB.Driver.IMongoCollection.InsertMany
  • Insert
  • Update


    Expand
    titleUpdate Methods Supported

    MongoDB.Driver.IMongoCollection.UpdateManyAsync

    MongoDB.Driver.IMongoCollection.UpdateOneAsync

    MongoDB.Driver.IMongoCollection.UpdateOne

    MongoDB.Driver.IMongoCollection.UpdateMany

    MongoDB.Driver.IMongoCollection.ReplaceOne

    MongoDB.Driver.IMongoCollection.ReplaceOneAsync

    MongoDB.Driver.IMongoCollectionExtensions.ReplaceOne

    MongoDB.Driver.IMongoCollectionExtensions.ReplaceOneAsync

    Update

    MongoDB.Driver.IMongoCollectionExtensions.UpdateMany

    MongoDB.Driver.IMongoCollectionExtensions.UpdateManyAsync

    MongoDB.Driver.IMongoCollectionExtensions.UpdateOne

    MongoDB.Driver.IMongoCollectionExtensions.UpdateOneAsync


    Select


    Expand
    titleSelect Methods Supported

    MongoDB.Driver.IMongoCollection.Find

    MongoDB.Driver.IMongoCollection.FindSync

    MongoDB.Driver.IMongoCollection.FindAsync

    FindOne

    FindOneAs

    Exists

    FindOneAndDelete

    FindOneAndDeleteAync

    FindOneAndReplace

    FindOneAndReplaceAsync

    FindOneAndUpdate

    FinOneAndUpdateAsync

    FindAllAs

    FindAll

    FindOneByIdAs

    BulkWrite

    BulkWriteAsync

    MongoDB.Driver.IMongoCollection.FindOneAndDelete

    MongoDB.Driver.IMongoCollection.FindOneAndDeleteAync

    MongoDB.Driver.IMongoCollection.FindOneAndReplace

    MongoDB.Driver.IMongoCollection.FindOneAndReplaceAsync

    MongoDB.Driver.IMongoCollection.FindOneAndUpdate

    MongoDB.Driver.IMongoCollection.FindOneAndUpdateAsync

    MongoDB.Driver.IMongoCollection.Count

    MongoDB.Driver.IMongoCollection.CountAsync

    MongoDB.Driver.IMongoCollection.Aggregate

    MongoDB.Driver.IMongoCollection.AggregateAsync

    MongoDB.Driver.IMongoCollection.BulkWrite

    MongoDB.Driver.IMongoCollection.BulkWriteAsync

    MongoDB.Driver.IMongoCollectionExtensions.ReplaceOne

    MongoDB.Driver.IMongoCollectionExtensions.ReplaceOneAsync

    MongoDB.Driver.IMongoCollectionExtensions.UpdateMany

    MongoDB.Driver.IMongoCollectionExtensions.UpdateManyAsync

    MongoDB.Driver.IMongoCollectionExtensions.UpdateOne

    MongoDB.Driver.IMongoCollectionExtensions.UpdateOneAsync

    MongoDB.Driver.IMongoCollectionExtensions.FindOneAndDelete

    MongoDB.Driver.IMongoCollectionExtensions.FindOneAndDeleteAsync

    MongoDB.Driver.IMongoCollectionExtensions.FindOneAndReplace

    MongoDB.Driver.IMongoCollectionExtensions.FindOneAndReplaceAsync

    MongoDB.Driver.IMongoCollectionExtensions.FindOneAndUpdate

    MongoDB.Driver.IMongoCollectionExtensions.FindOneAndUpdateAsync

    MongoDB.Driver.IMongoCollectionExtensions.Distinct

    MongoDB.Driver.IMongoCollectionExtensions.DistinctAsync

    MongoDB.Driver.IMongoCollectionExtensions.CountDocuments

    MongoDB.Driver.IMongoCollectionExtensions.CountDocumentsAsync

    MongoDB.Driver.IMongoCollectionExtensions.Find

    MongoDB.Driver.IMongoCollectionExtensions.Aggregate

    MongoDB.Driver.IMongoCollectionExtensions.Count

    MongoDB.Driver.IMongoCollectionExtensions.CountAsync


    Delete 


    Expand
    titleDelete Methods Supported

    MongoDB.Driver.IMongoCollection.DeleteMany

    MongoDB.Driver.IMongoCollection.DeleteManyAsync

    MongoDB.Driver.IMongoCollection.DeleteOne

    MongoDB.Driver.IMongoCollection.DeleteOneAsync

    MongoDB.Driver.IMongoCollection.FindOneAndDelete

    MongoDB.Driver.IMongoCollection.FindOneAndDeleteAsync

    Remove

    MongoDB.Driver.IMongoCollectionExtensions.DeleteOne

    MongoDB.Driver.IMongoCollectionExtensions.DeleteOneAsync

    MongoDB.Driver.IMongoCollectionExtensions.DeleteMany

    MongoDB.Driver.IMongoCollectionExtensions.DeleteManyAsync


    Objects

    DotNet MongoDB connection
    IconDescription

    Image Removed

    DotNet MongoDB database

    DotNet MongoDB collection

    Image Removed

    DotNet unknown MongoDB connection

    DotNet unknown MongoDB database

    DotNet unknown MongoDB collection

    ...

    Links are created for transaction and function point needs:

    Link typeSource and destination of link Methods supported
    parentLink 

    Between MongoDB

    Connection

    Database object and MongoDB

    Database

    Collection object

    • GetDatabase
    Between MongoDB
    Database object and MongoDB Collection object
    •  GetDatabase
    useLink
    Collection and Links
    • CreateCollection
    • CreateCollectionAsync
    • GetCollection

     useInsertLink
    Between the caller .NET Class / Method objects and MongoDB Collection objects

  • CreateCollection
  • CreateCollectionAsync
  • GetCollection

     useInsertLink


    • InsertOne
    • InsertOneAsync
    • InsertMany
    • InsertManyAsync
    • Insert
    useUpdateLink


    Expand
    titleUpdate Methods Supported

    UpdateManyAsync

    UpdateOneAsync

    UpdateOne

    UpdateMany

    ReplaceOne

    ReplaceOneAsync

    Update


     useSelectLink


    Expand
    titleSelect Methods Supported

    Find

    FindSync

    FindAsync

    FindOne

    FindOneAs

    Exists

    FindOneAndDelete

    FindOneAndDeleteAync

    FindOneAndReplace

    FindOneAndReplaceAsync

    FindOneAndUpdate

    FinOneAndUpdateAsync

    FindAllAs

    FindAll

    FindOneByIdAs

    BulkWrite

    BulkWriteAsync


    useDeleteLink 


    Expand
    titleDelete Method Supported

    DeleteMany
    DeleteManyAsync
    DeleteOne
    DeleteOneAsync
    FindOneAndDelete
    FindOneAndDeleteAsync

    Remove


    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.

    ...

    Database and Collection Creation

    ...

    Expand
    titleDatabase and Collection


    Code Block
    languagec#
    titleDatabase and Collection
    public
    static void 
    Aggregate
    InsertOneInMongoDB()
            {             var agbrands
    
            {
            
                MongoClient client = new MongoClient(
    ).GetDatabase("Banks").GetCollection<BsonDocument>("albarakacomtr_FollowerTweet") .Aggregate().Group(
    "mongodb://127.0.0.1:27017");
              
         
    new
     
    BsonDocument
     
    {
     
    {
     
    "_id",
     
    "$url.expanded_url"
     
    },                   
     
    { "count", new BsonDocument("$sum", 1) } }).ToListAsync().Result;          }

    Image Removed

    IMongoDatabase db = client.GetDatabase("TestDb1");
         
                IMongoCollection<Person> persons = db.GetCollection<Person>("Persons");
                IMongoCollection<Dog> dogs = db.GetCollection<Dog>("Dogs");
    }

    Image Added

    Insert Operation

    Expand
    titleInsert operation


    Code Block
    languagec#
    titleInsert
    public void InsertBson() { MongoDB.Driver.MongoClient mc
    {
                MongoClient client = new 
    MongoDB.Driver.MongoClient();         var
    MongoClient("mongodb://127.0.0.1:27017");
                IMongoDatabase db = 
    mc
    client.GetDatabase("
    Test
    TestDb1");
            var col
    
                IMongoCollection<BsonDocument> dogs = db.GetCollection<BsonDocument>("
    Brand
    Dogs");
    
        
            var
     
    brand
     
    =
     
    new
     
    BsonDocument
     
    {
     
    {
     
    "Id",
     
    2
    string 
    },
    json 
    {
    = "{Name
    ", "test" } };         col.InsertOne(brand); }

    ...

    :'大黄',Age:10,Weight:50}";
                BsonDocument d1 = BsonDocument.Parse(json);//解析Json数据
                dogs.InsertOne(d1);
    
    }

    Image Added

    Delete Operation

    Expand
    titleDelete Operation


    Code Block
    languagec#
    titleDelete
     public void 
    Delete
    DeleteAllPurchases()
    
           
     
    {
     
               
     
    MongoClient
     
    mc =
     
    new
     
    MongoClient();
     
               
     
    var
    {
    
    db
     
    =
     
    mc.GetServer().GetDatabase("Test");
     
              
     
     var
     
    col
     
    =
     
    db.GetCollection<Brand>("Brand");
     
               
     
    var
     
    filt
     
    =
     
    Builders<Brand>
    MyShoppingCollection.
    Filter.Eq("Id"
    DeleteMany(FilterDefinition<PurchaseBson>.Empty, 
    1
    null);
         
               
     
    col.DeleteOne(filt);
     
           
     }

    ...

    Image Added

    Select Operation

    c#Select
    Code Block
    language
    Expand
    titleSelect Operation


    Code Block
    title
    Delete
    public 
    void
    PurchaseBson[] 
    Read
    FindPurchases()
      
           
     
    {
     
               
     
    MongoDB.Driver.MongoClient
     
    mc
     
    =
     
    new MongoDB.Driver.MongoClient();             var db = mc.GetDatabase("Test");             var col = db.GetCollection<Brand>("Brand");             var filter = Builders<Brand>.Filter.Eq("Id", 1);             var projection = Builders<Brand>.Projection.Include("Name");             var sort = Builders<Brand>.Sort.Descending("Name");             var brand = col.Find(filter).Project(projection).Sort(sort);         }

    ...

    {
                var purchases = MyShoppingCollection.Find(FilterDefinition<PurchaseBson>.Empty, null).ToList();
                return purchases.ToArray();
            }

    Image Added

    Update Operation

    Expand
    titleUpdate Operation


    Code Block
    languagec#
    titleUpdate
     public 
    void
    async Task<IActionResult> Update()
    
           
            {
                MongoClient mc = new MongoClient();             var db3 = mc.GetDatabase("Test");             var col = db3.GetCollection<Brand>("Brand");             var filt = Builders<Brand>.Filter.Eq("Id", 1);             var upd = Builders<Brand>.Update.Set("Name", "Test1");             col.UpdateManyAsync(filt, upd).Wait();         }

    Image Removed

    Violations in AED

    Image Removed

    Evolution

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

    Limitations

    • Connection, 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 in the config files
    • Only files consisting of relevant MongoDB imports are processed further for analysing. In a case, where a file uses reference of another file / namespace which in turn uses relevant import, then file will not be analysed.

    Future Development

    ...

    
                var query = from k in (from a in _context.Books.AsQueryable()
                                        where a.Title == "Test Book 2"
                                        from b in a.Posts
                                        select b)
                             where k.Title == "Second One"
                             select k;
                var result = await query.FirstOrDefaultAsync();
                result.ReadCount = 5;
    
                _context.Books
                    .FindOneAndUpdate(x => x.Title == "Test Book 2" && x.Posts.Any(p => p.Title == "Second One"),
                                        Builders<Book>.Update.Set(x => x.Posts[-1], result));
    
                return Redirect("/");
            }
    
    

    Image Added

    Violations in CAST Engineering Dashboard

    The CAST Engineering Dashboard recognises code violations in source applications.

    Image Added

    Evolution

    • Database and collection objects are resolved in maximum cases
    • Supported all crud links for the library Mongodb.driver 

    Limitations

    • Db and Collections are resolved in following situation: 
      • Anywhere in the .cs files 
    • Query methods are not supported 

    Future Development

    • Support Query methods
    • Resolve Database and Collection name from JSON file