Update mongodb

This commit is contained in:
sunkaixuan
2025-05-02 16:30:22 +08:00
parent dc0e1af9f8
commit 6d854a492e
15 changed files with 396 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MongoDb.Ado.data
{
public class QueryAggregateHandlerAsync : IQueryHandlerAsync
{
public async Task<DbDataReader> HandlerAsync(IMongoCollection<BsonDocument> collection, BsonValue doc)
{
// 解析 JSON 字符串为 BsonArray
var pipeline = doc.AsBsonArray; ;
// 构建聚合管道
var aggregateFluent = collection.Aggregate<BsonDocument>(pipeline.Select(stage => new BsonDocument(stage.AsBsonDocument)).ToArray());
// 执行聚合查询并返回 DbDataReader
var cursor =await aggregateFluent.ToListAsync();
return new MongoDbBsonDocumentDataReader(cursor);
}
}
}