Like what we’re doing? Star us on GitHub!

Rest / Local API [where][in]

last year
1 3

Hello everyone,

Could someone please post an example of how to use 'where' 'in' query for Local and REST API?

Say I want to get 2 categories with specific IDs from the 'categories' collection. With local API this is what I am trying to do:

const result = await payload.find({
    collection: 'categories',
    where: {
        id: {
            in: ['619bea3fcc9ad5dd9692139f', '619bea2ccc9ad5dd96921377']

Result: it gives me all the categories from the collection.

What am I doing wrong?

Thank you!

  • jmikrut
    Payload Team
    last year

    Hey @vstarush — I can help here.

    Your syntax is right. Running a similarly formatted query against the new beta version of Payload returns 2 documents as expected.

    What version of Payload are you on? Can you try updating Payload to the most recent beta to re-try your test? The current beta, due to be released shortly, has fixed a few bugs due to querying by ID that arose from a new feature that we released a few versions back which allows users to define their own IDs for documents.

    Let me know if the new beta fixes it!

  • vstarush
    last year

    Hi jmikrut! Yes, thank you, the version had solved the issue.

    I was on 0.12.3 and it didn't work, but the 0.12.10-beta.0 works for Local API. Thank you! :)

    Do REST queries support 'in'/'not_in'? I tried this, but it didn't work:

    1 reply
    Payload Team
    last year

    Boom. You are on it! There was a leftover bug with our new implementation related to comma-delineated IDs.

    Install 0.12.11-beta.0 to get a fix! And thank you for bringing this up!

  • vstarush
    last year

    Hi @jmikrut

    Yep, I was away and missed the .11, but installed the .13 now. All works! :) Thanks so much for your help with this!!

Open the post
Continue the discussion in GitHub
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More