mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-19 22:49:35 +08:00
33 lines
980 B
C#
33 lines
980 B
C#
![]() |
using MongoDB.Bson.Serialization;
|
|||
|
using MongoDB.Bson;
|
|||
|
using MongoDB.Driver;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Text;
|
|||
|
|
|||
|
namespace MongoDb.Ado.data
|
|||
|
{
|
|||
|
public class DeleteManyHandler : IMongoOperationHandler
|
|||
|
{
|
|||
|
public int Handle(IMongoCollection<BsonDocument> collection, string json)
|
|||
|
{
|
|||
|
var documents = ParseJsonArray(json);
|
|||
|
int total = 0;
|
|||
|
foreach (var doc in documents)
|
|||
|
{
|
|||
|
var filter = doc["filter"].AsBsonDocument;
|
|||
|
var result = collection.DeleteMany(filter);
|
|||
|
total += (int)result.DeletedCount;
|
|||
|
}
|
|||
|
return total;
|
|||
|
}
|
|||
|
|
|||
|
private List<BsonDocument> ParseJsonArray(string json)
|
|||
|
{
|
|||
|
if (json.TrimStart().StartsWith("["))
|
|||
|
return BsonSerializer.Deserialize<List<BsonDocument>>(json);
|
|||
|
return new List<BsonDocument> { BsonDocument.Parse(json) };
|
|||
|
}
|
|||
|
}
|
|||
|
}
|