Page tree
Skip to end of metadata
Go to start of metadata

CAST supports MongoDB via its NoSQL for .NET extension. Details about how this support is provided for .NET source code is discussed below.

Supported Client Libraries

Supported Operations

Operation

Methods Supported

Create
  • CreateCollection
  • CreateCollectionAsync
  • GetCollection
Insert
  • InsertOne
  • InsertOneAsync
  • InsertManyAsync
  • InsertMany
  • Insert
Update
 Update Methods Supported

UpdateManyAsync

UpdateOneAsync

UpdateOne

UpdateMany

ReplaceOne

ReplaceOneAsync

Update

Select
 Select Methods Supported

Find

FindSync

FindAsync

FindOne

FindOneAs

Exists

FindOneAndDelete

FindOneAndDeleteAync

FindOneAndReplace

FindOneAndReplaceAsync

FindOneAndUpdate

FinOneAndUpdateAsync

FindAllAs

FindAll

FindOneByIdAs

BulkWrite

BulkWriteAsync

Delete 
 Delete Methods Supported

DeleteMany

DeleteManyAsync

DeleteOne

DeleteOneAsync

FindOneAndDelete

FindOneAndDeleteAsync

Remove

Objects

IconDescription

DotNet MongoDB connection

DotNet MongoDB database

DotNet MongoDB collection

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 object and MongoDB Database object


Between MongoDB Database object and MongoDB Collection object
  •  GetDatabase
useLinkBetween the caller .NET Class / Method objects and MongoDB Collection objects


  • CreateCollection
  • CreateCollectionAsync
  • GetCollection
 useInsertLink
  • InsertOne
  • InsertOneAsync
  • InsertMany
  • InsertManyAsync
  • Insert
useUpdateLink
 Update Methods Supported

UpdateManyAsync

UpdateOneAsync

UpdateOne

UpdateMany

ReplaceOne

ReplaceOneAsync

Update

 useSelectLink
 Select Methods Supported

Find

FindSync

FindAsync

FindOne

FindOneAs

Exists

FindOneAndDelete

FindOneAndDeleteAync

FindOneAndReplace

FindOneAndReplaceAsync

FindOneAndUpdate

FinOneAndUpdateAsync

FindAllAs

FindAll

FindOneByIdAs

BulkWrite

BulkWriteAsync

useDeleteLink 
 Delete 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.

Connection, Database and Collection Creation

Collection
public void Aggregate()
        {
            var agbrands = new MongoClient().GetDatabase("Banks").GetCollection<BsonDocument>("albarakacomtr_FollowerTweet") .Aggregate().Group( 		             new BsonDocument { { "_id", "$url.expanded_url" },                    { "count", new BsonDocument("$sum", 1) } }).ToListAsync().Result;
         }

Insert Operation

Insert
public void InsertBson()
{
	MongoDB.Driver.MongoClient mc = new MongoDB.Driver.MongoClient();
        var db = mc.GetDatabase("Test");
        var col = db.GetCollection<BsonDocument>("Brand");
        var brand = new BsonDocument { { "Id", 2 }, { "Name", "test" } };
        col.InsertOne(brand);
}

Delete Operation

Delete
public void Delete()
        {
            MongoClient mc = new MongoClient();
            var db = mc.GetServer().GetDatabase("Test");
            var col = db.GetCollection<Brand>("Brand");
            var filt = Builders<Brand>.Filter.Eq("Id", 1);
            col.DeleteOne(filt);
        }

Select Operation

Select
public void Read()
        {
            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);
        }

Update Operation

Update
public void 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();
        }

Violations in AED

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.
  • BulkWrite() and BulkWriteAsync() produce useLink between method and collection object

Future Development

  • Resolving the connection/database/collection name when passed as arguments in methods
  • No labels