Open mtrezza opened 2 years ago
Add a method
set
orupdate
toParse.Query
that if set executesParse.Query.first
as afindAndModify
in MongoDB.
I don't get this part, would the new query look like, Parse.Query.set( )
or Parse.Query.first(val, opts)
?
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.
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?
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
.
New Feature / Enhancement Checklist
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
orupdate
toParse.Query
that if set executesParse.Query.first
as afindAndModify
in MongoDB.Example Use Case
findAndModify
request for documents that are without a "being processed" flag, which returns one document which will be flagged as being processed immediately.Alternatives / Workarounds