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