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"; name = "ToDate";
if (name == "Contains" && methodCallExpression.Arguments.Count == 1 if (name == "Contains" && methodCallExpression.Arguments.Count == 1
&& methodCallExpression?.Object?.Type != null && methodCallExpression?.Object?.Type != null
&& typeof(IEnumerable).IsAssignableFrom(methodCallExpression.Object.Type)) && typeof(IEnumerable).IsAssignableFrom(methodCallExpression.Object.Type)
&& methodCallExpression.Object.Type!=UtilConstants.StringType)
{ {
name = "ContainsArray"; name = "ContainsArray";
} }

View File

@@ -736,6 +736,16 @@ namespace SqlSugar.MongoDb
var inDoc = new BsonDocument(name, new BsonDocument("$in", bsonArray)); var inDoc = new BsonDocument(name, new BsonDocument("$in", bsonArray));
return inDoc.ToJson(UtilMethods.GetJsonWriterSettings()); 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 else
{ {
// 数组表达式不是常量需生成MongoDB $in表达式数组字段为arrayExp判断itemExp是否在数组中 // 数组表达式不是常量需生成MongoDB $in表达式数组字段为arrayExp判断itemExp是否在数组中

View File

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