mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-07-17 01:46:18 +08:00
33 lines
1004 B
C#
33 lines
1004 B
C#
using MongoDB.Bson;
|
|
using MongoDB.Driver;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MongoDb.Ado.data
|
|
{
|
|
public class InsertHandlerAsync : IMongoOperationHandlerAsync
|
|
{
|
|
public HandlerContext context { get; set; }
|
|
public CancellationToken token { get; set; }
|
|
public string operation { get; set; }
|
|
public async Task<int> HandleAsync(IMongoCollection<BsonDocument> collection, string json)
|
|
{
|
|
var doc = BsonDocument.Parse(json);
|
|
if (context.IsAnyServerSession)
|
|
{
|
|
await collection.InsertOneAsync(context.ServerSession,doc, null, token);
|
|
}
|
|
else
|
|
{
|
|
await collection.InsertOneAsync(doc, null, token);
|
|
}
|
|
var objectId = doc["_id"].AsObjectId.ToString();
|
|
context.ids = new string[] { objectId };
|
|
return 1;
|
|
}
|
|
}
|
|
}
|