-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.0
-
Component/s: Operations
-
None
According to documentation, FindAndModify method should return original document by default.
But, it seems like, without specifying VersionReturned it returns modified document.
I looked at the MongoCollection class (in github) and at the line #560 it does a check. And, because the default value of VersionReturned property is null, then condition returns false. Therefore, Core.Operations.ReturnDocument.After will be used.
It case of using the following overloading of method:
public virtual FindAndModifyResult FindAndModify(IMongoQuery query, IMongoSortBy sortBy, IMongoUpdate update) { var args = new FindAndModifyArgs { Query = query, SortBy = sortBy, Update = update }; return FindAndModify(args); }
It doesn't specify which version of document should be returned.
According to this fragment:
var returnDocument = args.VersionReturned == FindAndModifyDocumentVersion.Original
? Core.Operations.ReturnDocument.Before
: Core.Operations.ReturnDocument.After;
It will be the same as:
var returnDocument = (FindAndModifyDocumentVersion?)null == FindAndModifyDocumentVersion.Original ? Core.Operations.ReturnDocument.Before : Core.Operations.ReturnDocument.After;
Need to add checking for null value and handle null as a default (original\before document) value.