Skip to content

Add a "containsAny" query #8485

@R3D347HR4Y

Description

@R3D347HR4Y

New Feature / Enhancement Checklist

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    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

    Issue actions