C# MongoDB 查询方法
public List<BsonDocument> GetCollectionByBillCode(string BillCode)
{
List<BsonDocument> list = new List<BsonDocument>();
// 根据集合名称获取集合
string collectionFullName = ConfigurationManager.AppSettings["collectionName"];
var collection = _database.GetCollection<BsonDocument>(collectionFullName);
var quert = "{ message : /" + BillCode + "/,level:/ERROR/}";
var filter = BsonSerializer.Deserialize<BsonDocument>(quert);
//filter = new BsonDocument("message", "/" + BillCode + "/");
// 查询集合中的文档
list = Task.Run(async () => await collection.Find(quert).ToListAsync()).Result;
//var list = collection.Find(filter).ToListAsync();
// 循环遍历输出
//list.ForEach(p =>
//{
// Console.WriteLine("编号:" + p["stuId"] + ",姓名:" + p["name"].ToString() + ",年龄:" + p["age"].ToString() + ",课程:" + p["subject"].ToString() + ",成绩:" + p["score"].ToString());
//});
return list;
}