parse-community / parse-community/parse-server
Add a "containsAny" query
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 21.4k
- Forks
- 4.8k
- Avg merge
- 7h 45m
- Merged PRs (30d)
- 11
Description
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
There is no way to do this currently apart from doing orQueries which seem to be expensive
Feature / Enhancement Description
The containsAny query would do the following:
You want to get all objects whose key would be an array that contains any of the values provided by the array given to the function
Example Use Case
Parse.Object 1 {arr: ["a", "b"]}
Parse.Object 2 {arr: ["b"]}
Parse.Object 3 {arr: ["c", "d"]}
Parse.Object 4 {arr: ["a", "d"]}
Parse.Query().containsAny("arr", ["b", "c"])
The objects matching this query would be: 1, 2, 3
Alternatives / Workarounds
You can use this code made by our good friend ChatGPT but I don't know if it would work well with long arrays:
const Parse = require('parse/node');
// Assuming you have initialized Parse using Parse.initialize()
async function queryObjectsContainedIn(query, key, values) {
const subqueries = bleIds.map((bleId) => {
return query.equalTo(key, values);
});
// Combine subqueries using an "or" query
const combinedQuery = Parse.Query.or(...subqueries);
try {
const results = await combinedQuery.find();
return results;
} catch (error) {
console.error('Error while fetching: ', error);
return [];
}
}
3rd Party References
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The requested entry point is Parse.Query().containsAny("arr", ["b", "c"]); start by tracing the existing array-query and orQueries behavior in Parse Server. Add coverage for the four-object example and verify that objects 1, 2, and 3 match while object 4 does not.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100