Skip to content

Support MongoDB's findAndModify #7819

@mtrezza

Description

@mtrezza
Member

New Feature / Enhancement Checklist

  • I am not disclosing a vulnerability.
    I am not just asking a question.
    I have searched through existing issues.

Current Limitation

Parse does not natively support a way to issue a query and in the same operation write to the found documents. This is a concept used to uniquely process documents in an environment with concurrent operations.

Feature / Enhancement Description

Add a method set or update to Parse.Query that if set executes Parse.Query.first as a findAndModify in MongoDB.

Example Use Case

  1. Request A is a findAndModify request for documents that are without a "being processed" flag, which returns one document which will be flagged as being processed immediately.
  2. Request B is the same as request A and has been issued at the time as request A. No document is returned, which ensures the same document is not being processed twice.

Alternatives / Workarounds

  • Use transactions, which may have an unnecessary performance impact
  • Directly access the DB adapter, see How to use Mongo's findOneAndUpdate. #4258
  • Maintain a custom DB connection, directly interacting with the DB driver

Activity

parse-github-assistant

parse-github-assistant commented on Feb 21, 2022

@parse-github-assistant

Thanks for opening this issue!

  • 🎉 We are excited about your ideas for improvement!
changed the title [-]Support MongoDB's findOneAndModify[/-] [+]Support MongoDB's findAndModify[/+] on Feb 21, 2022
added
bounty:$50Bounty applies for fixing this issue (Parse Bounty Program)
on Feb 21, 2022
added
bounty:$100Bounty applies for fixing this issue (Parse Bounty Program)
and removed
bounty:$50Bounty applies for fixing this issue (Parse Bounty Program)
on Oct 19, 2023
iMac7

iMac7 commented on May 16, 2024

@iMac7

Add a method set or update to Parse.Query that if set executes Parse.Query.first as a findAndModify in MongoDB.

I don't get this part, would the new query look like, Parse.Query.set( ) or Parse.Query.first(val, opts) ?

mtrezza

mtrezza commented on May 16, 2024

@mtrezza
MemberAuthor
const q = new Parse.Query();
q.equals("status", "upForGrabs");
q.set("status", "grabbed");
const obj = await q.first();

In a collection with N documents that match the query this query returns 1 matching document and at the same time sets status to grabbed, all in a single DB request using MongoDB's findAndModify operator.

We should look into the MongoDB docs to see whether set, update or modify make most sense semantically, to not cause confusion with other operators.

iMac7

iMac7 commented on Jun 14, 2024

@iMac7

I see that a findOneAndModify is available in parse server already. Should this be solved in the sdk by conditionally changing the operation that Parse.Query.first() executes?
Is there something to be done on the server?

mtrezza

mtrezza commented on Jun 14, 2024

@mtrezza
MemberAuthor

Not sure if Parse Server supports findOneAndModify yet, even though it may be used internally for some operations. This would need to be implemented in the REST API, and I guess as you said, the client SDK should use that endpoint conditionally if the query contains a set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bounty:$100Bounty applies for fixing this issue (Parse Bounty Program)type:featureNew feature or improvement of existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mtrezza@iMac7

        Issue actions

          Support MongoDB's findAndModify · Issue #7819 · parse-community/parse-server