mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-26 14:15:50 +08:00
Update mongodb
This commit is contained in:
@@ -9,19 +9,16 @@ namespace MongoDb.Ado.data
|
||||
{
|
||||
public class ExecuteScalarHandler
|
||||
{
|
||||
public object Handle(IMongoCollection<BsonDocument> collection, string json)
|
||||
public object Handle(string operation, IMongoCollection<BsonDocument> collection, string json)
|
||||
{
|
||||
var filter = string.IsNullOrWhiteSpace(json) ? FilterDefinition<BsonDocument>.Empty : BsonDocument.Parse(json);
|
||||
// 执行查询并限制返回一条记录
|
||||
var document = collection.Find(filter).FirstOrDefault();
|
||||
|
||||
// 如果查询到结果且文档非空,则获取第一个字段的值
|
||||
if (document != null && document.Elements.Any())
|
||||
using (var dbReader = new DbDataReaderFactory().Handle(operation, collection, json))
|
||||
{
|
||||
var firstElement = document.Elements.First(); // 获取第一个字段(列)
|
||||
return firstElement.Value; // 返回该字段的值
|
||||
}
|
||||
return null; //
|
||||
}
|
||||
if (dbReader.Read())
|
||||
{
|
||||
return dbReader.GetValue(0);
|
||||
}
|
||||
return null; //
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user