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

Mongodb.dotnet driver 2.x

Supported Operations

Operation

Methods Supported

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


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

MongoDB.Driver.IMongoCollectionExtensions.UpdateMany

MongoDB.Driver.IMongoCollectionExtensions.UpdateManyAsync

MongoDB.Driver.IMongoCollectionExtensions.UpdateOne

MongoDB.Driver.IMongoCollectionExtensions.UpdateOneAsync


Select


MongoDB.Driver.IMongoCollection.Find

MongoDB.Driver.IMongoCollection.FindSync

MongoDB.Driver.IMongoCollection.FindAsync

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 


MongoDB.Driver.IMongoCollection.DeleteMany

MongoDB.Driver.IMongoCollection.DeleteManyAsync

MongoDB.Driver.IMongoCollection.DeleteOne

MongoDB.Driver.IMongoCollection.DeleteOneAsync

MongoDB.Driver.IMongoCollection.FindOneAndDelete

MongoDB.Driver.IMongoCollection.FindOneAndDeleteAsync

MongoDB.Driver.IMongoCollectionExtensions.DeleteOne

MongoDB.Driver.IMongoCollectionExtensions.DeleteOneAsync

MongoDB.Driver.IMongoCollectionExtensions.DeleteMany

MongoDB.Driver.IMongoCollectionExtensions.DeleteManyAsync


Objects

IconDescription

DotNet MongoDB database

DotNet MongoDB collection

DotNet unknown MongoDB database

DotNet unknown MongoDB collection

Links

Links are created for transaction and function point needs:

Link typeSource and destination of link Methods supported
parentLink 

Between MongoDB Database object and MongoDB Collection object

  • GetDatabase
Between MongoDB Collection and Links
  • CreateCollection
  • CreateCollectionAsync
  • GetCollection

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


  • InsertOne
  • InsertOneAsync
  • InsertMany
  • InsertManyAsync
  • Insert
useUpdateLink


UpdateManyAsync

UpdateOneAsync

UpdateOne

UpdateMany

ReplaceOne

ReplaceOneAsync

Update


 useSelectLink


Find

FindSync

FindAsync

FindOne

FindOneAs

FindOneAndDelete

FindOneAndDeleteAync

FindOneAndReplace

FindOneAndReplaceAsync

FindOneAndUpdate

FinOneAndUpdateAsync

BulkWrite

BulkWriteAsync


useDeleteLink 


DeleteMany
DeleteManyAsync
DeleteOne
DeleteOneAsync
FindOneAndDelete
FindOneAndDeleteAsync


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


static void InsertOneInMongoDB()
        {
        
            MongoClient client = new MongoClient("mongodb://127.0.0.1:27017");
          
            IMongoDatabase db = client.GetDatabase("TestDb1");
     
            IMongoCollection<Person> persons = db.GetCollection<Person>("Persons");
            IMongoCollection<Dog> dogs = db.GetCollection<Dog>("Dogs");
}

Insert Operation


{
            MongoClient client = new MongoClient("mongodb://127.0.0.1:27017");
            IMongoDatabase db = client.GetDatabase("TestDb1");
            IMongoCollection<BsonDocument> dogs = db.GetCollection<BsonDocument>("Dogs");

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

}

Delete Operation


 public void DeleteAllPurchases()
        {
            MyShoppingCollection.DeleteMany(FilterDefinition<PurchaseBson>.Empty, null);
        }

Select Operation


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

Update Operation


 public async Task<IActionResult> Update()
        {
            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("/");
        }

Violations in CAST Engineering Dashboard

The CAST Engineering Dashboard recognises code violations in source applications.

Evolution

Limitations

Future Development