Rule Definition
UAs the db.collection.ensureIndex() is deprecated since version 3.0.0 and the db.collection.ensureIndex() is now an alias for db.collection.createIndex() it is recommended to always use db.collection.createIndex() rather than db.collection.ensureIndex() to create new indexes.
Indeed Using deprecated MongoDB API could lead to security compliancy issues.
Remediation
Use db.collection.createIndex() rather than db.collection.ensureIndex() to create new indexes.
Violation Code Sample
var server = MongoServer.Create("mongodb://localhost");
var db = server.GetDatabase("myapp");
var users = db.GetCollection<User>("users");
users.EnsureIndex(new IndexKeysBuilder().Ascending("EmailAddress"));
Fixed Code Sample
var client = new MongoClient("mongodb://localhost");
var db = client.GetServer().GetDatabase("myapp");
var collection = db.GetCollection<User>("users");
collection.CreateIndex(new IndexKeysBuilder().Ascending("EmailAddress"), IndexOptions.SetBackground(true));
Related Technologies
Technical Criterion
Architecture - OS and Platform Independence
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.