diff --git a/Core.Blueprint.Mongo/Contracts/ICollectionRepository.cs b/Core.Blueprint.Mongo/Contracts/ICollectionRepository.cs
index 92dd967..66a47c0 100644
--- a/Core.Blueprint.Mongo/Contracts/ICollectionRepository.cs
+++ b/Core.Blueprint.Mongo/Contracts/ICollectionRepository.cs
@@ -104,11 +104,13 @@ namespace Core.Blueprint.Mongo
void ReplaceOne(TDocument document);
///
- /// Asynchronously replaces an existing document with a new one.
+ /// Asynchronously replaces an existing document in the collection and returns the updated version.
///
- /// The document to replace the existing one.
- /// A representing the asynchronous operation.
- Task ReplaceOneAsync(TDocument document);
+ /// The document with the updated data. Its _Id is used to locate the existing document.
+ ///
+ /// The updated document if the replacement was successful; otherwise, null if no matching document was found.
+ ///
+ Task ReplaceOneAsync(TDocument document);
///
/// Deletes a single document by the provided filter expression.
diff --git a/Core.Blueprint.Mongo/Repositories/CollectionRepository.cs b/Core.Blueprint.Mongo/Repositories/CollectionRepository.cs
index 3f5f6a0..a03cfdc 100644
--- a/Core.Blueprint.Mongo/Repositories/CollectionRepository.cs
+++ b/Core.Blueprint.Mongo/Repositories/CollectionRepository.cs
@@ -175,16 +175,27 @@ namespace Core.Blueprint.Mongo
}
///
- /// Asynchronously replaces an existing document in the collection.
+ /// Asynchronously replaces an existing document in the collection and returns the updated version.
///
- /// The document with the updated data.
- /// A task that represents the asynchronous operation.
- public virtual async Task ReplaceOneAsync(TDocument document)
+ /// The document with the updated data. Its _Id is used to locate the existing document.
+ ///
+ /// The updated document if the replacement was successful; otherwise, null if no matching document was found.
+ ///
+ public virtual async Task ReplaceOneAsync(TDocument document)
{
var filter = Builders.Filter.Eq(doc => doc._Id, document._Id);
- await _collection.FindOneAndReplaceAsync(filter, document);
+
+ var options = new FindOneAndReplaceOptions
+ {
+ ReturnDocument = ReturnDocument.After // return the updated document
+ };
+
+ var result = await _collection.FindOneAndReplaceAsync(filter, document, options);
+
+ return result;
}
+
///
/// Deletes a single document from the collection based on the provided filter expression.
///