Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1836

Legacy v2.x FindAndModify operation returns modified document by default (instead of original)

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4.1
    • 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.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            MaKCbIMKo Maksim Krautsou [X]
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: