Update Mongodb

This commit is contained in:
sunkaixuan
2025-06-12 14:07:28 +08:00
parent b6c8b64f8c
commit a7837ddf8f
3 changed files with 25 additions and 13 deletions

View File

@@ -127,6 +127,17 @@ namespace MongoDbTest
max=SqlFunc.AggregateMax(it.Id),
min=SqlFunc.AggregateMin(it.Id)
}).ToList();
var list14 = db.Queryable<OrderInfo>()
.GroupBy(it => new { it.Name ,it.Price })
.Select(it => new
{
key = it.Name,
Prie=it.Price,
groupCount = SqlFunc.AggregateCount(it.Id),
max = SqlFunc.AggregateMax(it.Id),
min = SqlFunc.AggregateMin(it.Id)
}).ToList();
//测试生成SQL性能
TestSqlBuilder(db);
}

View File

@@ -1,5 +1,5 @@
using MongoDbTest;
//MongoDb还在开发中预计5月30号前可以使用
//MongoDb还在开发中预计6月30号前可以使用
OrmTest.Init();
AdoTest.Init();
ExpTest.Init();

View File

@@ -116,7 +116,6 @@ namespace SqlSugar.MongoDb
}
#endregion
#region Select
if (this.SelectValue is Expression expression)
{
@@ -130,7 +129,6 @@ namespace SqlSugar.MongoDb
}
#endregion
#region GroupBy
if (this.GroupByValue.HasValue())
{
@@ -144,18 +142,21 @@ namespace SqlSugar.MongoDb
var selectItem = match.Groups[1].Value;
selectItems.Add(selectItem);
}
var jsonPart = Regex.Split(this.GroupByValue, UtilConstants.ReplaceCommaKey)
var jsonPart = "["+Regex.Split(this.GroupByValue, UtilConstants.ReplaceCommaKey)
.First()
.TrimEnd('(')
.Replace("GROUP BY ", "");
.Replace("GROUP BY ", "")+"]";
var fieldNames = new List<string>();
var bson = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonDocument>(jsonPart);
var bsonArray = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<BsonArray>(jsonPart);
foreach (BsonDocument bson in bsonArray)
{
if (bson.Contains("fieldName"))
{
var field = bson["fieldName"].AsString;
operations[operations.Count - 1] = operations[operations.Count - 1].Replace($"\"${field}\"", $"\"$_id.{field}\"");
fieldNames.Add(field);
}
}
// 构造 _id 部分:支持多字段形式
var groupId = new BsonDocument();
foreach (var field in fieldNames)