var mongodb = new MongoClient("mongodb://127.0.0.1:27017");//MongoServer.Create();//創建鏈接
var mongoServer = mongodb.GetServer();
var database = mongoServer.GetDatabase("lx");
var collection = database.GetCollection<MyClass>("MyClass");//打開表
var query1 = Query.Matches("Name", new BsonRegularExpression(@"/^張三5623/"));//創建模糊查詢的查詢條件---Query類所在命名空間 MongoDB.Driver.Builders
var now = DateTime.Now;
var data = collection.Find(query1).Count();//統計查詢出的數據數量
Console.WriteLine(data.ToString());
Console.WriteLine((DateTime.Now - now).TotalMilliseconds.ToString());//統計耗時
測試環境:I7處理器 8G內存,數據量500W,使用官方的驅動
數據結構
public class MyClass
{
public ObjectId _id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Address { get; set; }
}
耗時:平均 3372.1929毫秒
