2025-05-02 16:30:22 +08:00
|
|
|
|
using MongoDB.Bson;
|
|
|
|
|
using MongoDB.Driver;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2025-06-10 17:46:57 +08:00
|
|
|
|
using System.Threading;
|
2025-05-02 16:30:22 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MongoDb.Ado.data
|
|
|
|
|
{
|
|
|
|
|
public class InsertHandlerAsync : IMongoOperationHandlerAsync
|
|
|
|
|
{
|
2025-07-09 12:06:43 +08:00
|
|
|
|
public HandlerContext context { get; set; }
|
2025-06-10 17:46:57 +08:00
|
|
|
|
public CancellationToken token { get; set; }
|
2025-05-02 16:55:48 +08:00
|
|
|
|
public string operation { get; set; }
|
2025-05-02 16:30:22 +08:00
|
|
|
|
public async Task<int> HandleAsync(IMongoCollection<BsonDocument> collection, string json)
|
|
|
|
|
{
|
|
|
|
|
var doc = BsonDocument.Parse(json);
|
2025-07-09 12:07:56 +08:00
|
|
|
|
await collection.InsertOneAsync(doc,null,token);
|
|
|
|
|
var objectId = doc["_id"].AsObjectId.ToString();
|
|
|
|
|
context.ids = new string[] { objectId };
|
2025-05-02 16:30:22 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|