Update mongodb

This commit is contained in:
sunkaixuan 2025-06-16 16:44:48 +08:00
parent 5032a7d1fe
commit 92f5c68c57
2 changed files with 6 additions and 2 deletions

View File

@ -64,7 +64,7 @@ namespace SqlSugar.MongoDb
} }
public static readonly List<string> AllowedDateParts = new List<string>() public static readonly List<string> AllowedDateParts = new List<string>()
{ {
"Date", "Year", "Month", "Day", "Hour", "Minute", "Second", "Millisecond" "Date","DayOfWeek", "Year", "Month", "Day", "Hour", "Minute", "Second", "Millisecond"
}; };
} }
} }

View File

@ -386,7 +386,11 @@ namespace SqlSugar.MongoDb
case DateType.Millisecond: case DateType.Millisecond:
return new BsonDocument("$millisecond", $"${itemValue}").ToJson(UtilMethods.GetJsonWriterSettings()); return new BsonDocument("$millisecond", $"${itemValue}").ToJson(UtilMethods.GetJsonWriterSettings());
case DateType.Weekday: case DateType.Weekday:
return new BsonDocument("$week", $"${itemValue}").ToJson(UtilMethods.GetJsonWriterSettings()); return new BsonDocument("$subtract", new BsonArray
{
new BsonDocument("$dayOfWeek", $"${itemValue}"),
1
}).ToJson(UtilMethods.GetJsonWriterSettings());
case DateType.Quarter: case DateType.Quarter:
// MongoDB 没有直接的quarter操作符需自定义表达式 // MongoDB 没有直接的quarter操作符需自定义表达式
var expr = new BsonDocument("$add", new BsonArray var expr = new BsonDocument("$add", new BsonArray