(feature): allow empty collections for insert, update and upsert many
This commit is contained in:
parent
993cb90f8a
commit
37e64d7d24
@ -46,6 +46,11 @@ namespace MaksIT.MongoDB.Linq.Abstractions {
|
|||||||
#region InsertMany
|
#region InsertMany
|
||||||
protected virtual async Task<Result<List<TDtoKey>?>> InsertManyAsync(List<TDtoDocument> documents, IClientSessionHandle? session) {
|
protected virtual async Task<Result<List<TDtoKey>?>> InsertManyAsync(List<TDtoDocument> documents, IClientSessionHandle? session) {
|
||||||
try {
|
try {
|
||||||
|
// Check if the documents list is empty
|
||||||
|
if (documents.Count == 0) {
|
||||||
|
return Result<List<TDtoKey>?>.Ok(new List<TDtoKey>());
|
||||||
|
}
|
||||||
|
|
||||||
if (session != null)
|
if (session != null)
|
||||||
await Collection.InsertManyAsync(session, documents);
|
await Collection.InsertManyAsync(session, documents);
|
||||||
else
|
else
|
||||||
@ -90,6 +95,11 @@ namespace MaksIT.MongoDB.Linq.Abstractions {
|
|||||||
Expression<Func<TDtoDocument, bool>> predicate,
|
Expression<Func<TDtoDocument, bool>> predicate,
|
||||||
IClientSessionHandle? session) {
|
IClientSessionHandle? session) {
|
||||||
try {
|
try {
|
||||||
|
// Check if the documents list is empty
|
||||||
|
if (documents.Count == 0) {
|
||||||
|
return Result<List<TDtoKey>?>.Ok(new List<TDtoKey>());
|
||||||
|
}
|
||||||
|
|
||||||
// Step 1: Find the documents that already exist based on the predicate
|
// Step 1: Find the documents that already exist based on the predicate
|
||||||
List<TDtoDocument> existingDocuments;
|
List<TDtoDocument> existingDocuments;
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
@ -161,6 +171,11 @@ namespace MaksIT.MongoDB.Linq.Abstractions {
|
|||||||
Expression<Func<TDtoDocument, bool>> predicate,
|
Expression<Func<TDtoDocument, bool>> predicate,
|
||||||
IClientSessionHandle? session) {
|
IClientSessionHandle? session) {
|
||||||
try {
|
try {
|
||||||
|
// Check if the documents list is empty
|
||||||
|
if (documents.Count == 0) {
|
||||||
|
return Result<List<TDtoKey>?>.Ok(new List<TDtoKey>());
|
||||||
|
}
|
||||||
|
|
||||||
// Deletion
|
// Deletion
|
||||||
if (session != null)
|
if (session != null)
|
||||||
await Collection.DeleteManyAsync(session, predicate);
|
await Collection.DeleteManyAsync(session, predicate);
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<!-- NuGet package metadata -->
|
<!-- NuGet package metadata -->
|
||||||
<PackageId>MaksIT.MongoDB.Linq</PackageId>
|
<PackageId>MaksIT.MongoDB.Linq</PackageId>
|
||||||
<Version>1.0.6</Version>
|
<Version>1.0.7</Version>
|
||||||
<Authors>Maksym Sadovnychyy</Authors>
|
<Authors>Maksym Sadovnychyy</Authors>
|
||||||
<Company>MAKS-IT</Company>
|
<Company>MAKS-IT</Company>
|
||||||
<Product>MaksIT.MongoDB.Linq</Product>
|
<Product>MaksIT.MongoDB.Linq</Product>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user