mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-06-28 04:35:29 +08:00
Update mongodb
This commit is contained in:
parent
ea02771199
commit
fffbe29151
@ -14,6 +14,7 @@ namespace MongoDb.Ado.data
|
||||
{
|
||||
public class DbDataReaderFactoryAsync
|
||||
{
|
||||
public CancellationToken token { get; set; }
|
||||
public readonly static Dictionary<string, IQueryHandlerAsync> Items = new Dictionary<string, IQueryHandlerAsync>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ "find", new QueryFindHandlerAsync() },
|
||||
@ -28,7 +29,8 @@ namespace MongoDb.Ado.data
|
||||
{
|
||||
await ExecuteHandlerFactoryAsync.HandlerAsync(operation, json, collection, cancellationToken);
|
||||
return new DataTable().CreateDataReader();
|
||||
}
|
||||
}
|
||||
handler.token = cancellationToken;
|
||||
return await handler.HandlerAsync(collection, doc);
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,15 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using System.Data.Common;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDb.Ado.data
|
||||
{
|
||||
public interface IQueryHandlerAsync
|
||||
{
|
||||
CancellationToken token { get; set; }
|
||||
|
||||
Task<DbDataReader> HandlerAsync(IMongoCollection<BsonDocument> collection, BsonValue doc);
|
||||
}
|
||||
}
|
@ -6,12 +6,14 @@ using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDb.Ado.data
|
||||
{
|
||||
public class QueryAggregateHandlerAsync : IQueryHandlerAsync
|
||||
{
|
||||
public CancellationToken token { get; set; }
|
||||
public async Task<DbDataReader> HandlerAsync(IMongoCollection<BsonDocument> collection, BsonValue doc)
|
||||
{
|
||||
// 解析 JSON 字符串为 BsonArray
|
||||
@ -21,7 +23,7 @@ namespace MongoDb.Ado.data
|
||||
var aggregateFluent = collection.Aggregate<BsonDocument>(pipeline.Select(stage => new BsonDocument(stage.AsBsonDocument)).ToArray());
|
||||
|
||||
// 执行聚合查询并返回 DbDataReader
|
||||
var cursor =await aggregateFluent.ToListAsync();
|
||||
var cursor =await aggregateFluent.ToListAsync(token);
|
||||
return new MongoDbBsonDocumentDataReader(cursor);
|
||||
}
|
||||
}
|
||||
|
@ -5,12 +5,14 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MongoDb.Ado.data
|
||||
{
|
||||
public class QueryFindHandlerAsync : IQueryHandlerAsync
|
||||
{
|
||||
public CancellationToken token { get; set; }
|
||||
public async Task<DbDataReader> HandlerAsync(IMongoCollection<BsonDocument> collection, BsonValue doc)
|
||||
{
|
||||
BsonDocument filter;
|
||||
@ -37,7 +39,7 @@ namespace MongoDb.Ado.data
|
||||
if (projection != null)
|
||||
findFluent = findFluent.Project<BsonDocument>(projection);
|
||||
|
||||
var cursor =await findFluent.ToListAsync();
|
||||
var cursor =await findFluent.ToListAsync(token);
|
||||
return new MongoDbBsonDocumentDataReader(cursor); // 你要确保这个类支持逐行读取 BsonDocument
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user