Fix Retrieve updated document in ReplaceOneAsync method
This commit is contained in:
		| @@ -175,16 +175,27 @@ namespace Core.Blueprint.Mongo | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Asynchronously replaces an existing document in the collection. | ||||
|         /// Asynchronously replaces an existing document in the collection and returns the updated version. | ||||
|         /// </summary> | ||||
|         /// <param name="document">The document with the updated data.</param> | ||||
|         /// <returns>A task that represents the asynchronous operation.</returns> | ||||
|         public virtual async Task ReplaceOneAsync(TDocument document) | ||||
|         /// <param name="document">The document with the updated data. Its _Id is used to locate the existing document.</param> | ||||
|         /// <returns> | ||||
|         /// The updated document if the replacement was successful; otherwise, <c>null</c> if no matching document was found. | ||||
|         /// </returns> | ||||
|         public virtual async Task<TDocument?> ReplaceOneAsync(TDocument document) | ||||
|         { | ||||
|             var filter = Builders<TDocument>.Filter.Eq(doc => doc._Id, document._Id); | ||||
|             await _collection.FindOneAndReplaceAsync(filter, document); | ||||
|  | ||||
|             var options = new FindOneAndReplaceOptions<TDocument> | ||||
|             { | ||||
|                 ReturnDocument = ReturnDocument.After // return the updated document | ||||
|             }; | ||||
|  | ||||
|             var result = await _collection.FindOneAndReplaceAsync(filter, document, options); | ||||
|  | ||||
|             return result; | ||||
|         } | ||||
|  | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Deletes a single document from the collection based on the provided filter expression. | ||||
|         /// </summary> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user