Update mongodb

This commit is contained in:
sunkaixuan
2025-09-08 20:22:24 +08:00
parent 338b340a23
commit e8fe6d4629
3 changed files with 14 additions and 3 deletions

View File

@@ -260,7 +260,8 @@ namespace SqlSugar.MongoDb
name = "ToDate";
if (name == "Contains" && methodCallExpression.Arguments.Count == 1
&& methodCallExpression?.Object?.Type != null
&& typeof(IEnumerable).IsAssignableFrom(methodCallExpression.Object.Type))
&& typeof(IEnumerable).IsAssignableFrom(methodCallExpression.Object.Type)
&& methodCallExpression.Object.Type!=UtilConstants.StringType)
{
name = "ContainsArray";
}

View File

@@ -736,6 +736,16 @@ namespace SqlSugar.MongoDb
var inDoc = new BsonDocument(name, new BsonDocument("$in", bsonArray));
return inDoc.ToJson(UtilMethods.GetJsonWriterSettings());
}
else if (ExpressionTool.GetParameters(itemExp).Count == 0)
{
// itemExp 是常量表达式arrayExp 是字段表达式
var value =UtilMethods.MyCreate(ExpressionTool.DynamicInvoke(itemExp));
BsonValue arrayField = new ExpressionVisitor(context).Visit(arrayExp);
// 构建 MongoDB $in 查询表达式,判断 value 是否在 arrayField 字段数组中
var inDoc = new BsonDocument(arrayField.ToString(), new BsonDocument( "$in",new BsonArray() { value } ));
return inDoc.ToJson(UtilMethods.GetJsonWriterSettings());
}
else
{
// 数组表达式不是常量需生成MongoDB $in表达式数组字段为arrayExp判断itemExp是否在数组中
@@ -744,7 +754,7 @@ namespace SqlSugar.MongoDb
// 获取数组字段名
BsonValue arrayField = new ExpressionVisitor(context).Visit(arrayExp);
// 构建MongoDB的 $in 查询表达式,格式为 { "$in": [ "$_id", "$$let_RoleIds" ] }
var inArray = new BsonArray { name, arrayField };
var inArray = new BsonArray { name, arrayField };
var inDoc = new BsonDocument("$in", inArray);
return inDoc.ToJson(UtilMethods.GetJsonWriterSettings());
}

View File

@@ -308,7 +308,7 @@ namespace SqlSugar.MongoDb
// $unwind
BsonValue unwindDoc = null;
if (item.JoinType == JoinType.Left&&isEasyJoin)
if (item.JoinType == JoinType.Left)
{
unwindDoc = new BsonDocument("$unwind", new BsonDocument
{