嗨,我正在尝试创建一个通用方法来从数据库返回单个值我不确定将返回结果放在哪里,值作为 BSON 文档返回。我需要其中的 1 个值....
public static string SearchMongoSingleValue(string key, string value, string ducument, string datatable)
{
var connectionString = "mongodb://localhost";
var client = new MongoClient(connectionString);
var server = client.GetServer();
var database = server.GetDatabase(datatable);
var collection = database.GetCollection(ducument);
var query = Query.EQ(key, value);
var oneDocument = collection.FindOne(query);
return oneDocument[value];
谢谢