Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-5241

Introduce returnRawResult option in findAndModify family of methods

    • 3
    • Not Needed
    • Needed
    • Hide

      The findOneAnd... methods now accept a new option, includeResultMetadata, which defaults to true and returns a ModifyResult. When set to false, it will return the modified document.

      Example:

      await collection.findOneAndDelete({ a: 1 }, { includeResultMetadata: false }); // returns the deleted document { a: 1 }
      
      Show
      The findOneAnd... methods now accept a new option, includeResultMetadata , which defaults to true and returns a ModifyResult . When set to false , it will return the modified document. Example: await collection.findOneAndDelete({ a: 1 }, { includeResultMetadata: false }); // returns the deleted document { a: 1 }

      Use Case

      As a driver engineer I want to reduce the difference between node and common driver's spec. Currently our findOneAnd* methods only return a wrapped type for the findOneAnd* functions.

      findOneAnd* methods should support an additional option of returnRawResult: [true|false] allowing the ModifyResult or the modified document to be returned instead.

      User Impact

      • Introduces a new option to return the spec compliant version of findAndModify*
      • Default behavior will be left unchanged in v5 and will be flipped in v6 (see NODE-3568)

      Dependencies

      • None

      Unknowns

      • None

      Acceptance Criteria

      Implementation Requirements

      • Undeprecate ModifyResult
      • Add an option to toggle returning the raw result from server in all findOneAnd* APIs (`returnRawResult`)
        • Ensure null is returned if no results are found
      • Add API and official guide documentation to what the option does

      Dev note: returnRawResult is not meant to be prescriptive - the server returns a write_ops::FindAndModifyCommandReply, internally the driver returns a ModifyResult but our flag should make it clearer as to what is being returned.

      Testing Requirements

      • Add unit tests for the default and explicit true/false behavior of the new option
      • Add typescript tests for the default and explicit true/false behavior of the new option

      Documentation Requirements

      • DOCSP ticket to add the new option to official docs
      • API docs should clearly explain the option

      Follow Up Requirements

      • Give mongoose a heads up to explicitly set the option to preempt breaking changes ahead of V6
      • If we use a different option name, update NODE-3568

        There are no Sub-Tasks for this issue.

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            daria.pardue@mongodb.com Daria Pardue
            Bailey Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: