Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

How do I conditionally query items inside an array?

default discord avatar
acemaker0011 months ago

Let's say my data is structured like this in Payload...


{ "carts": [ { "items": [{ "name": "banana" }] }, { "items": [{ "name": "banana" }, { "name": "apple" }] }, { "items": [{ "name": "orange" }] } ] }

I want to query only items that have the name "banana." How would I do that? Is it even possible? I've been trying to figure it out for the past 2 hours, but nothing is working.



Alright, I found a solution, but it's for my particular case, not for the example I gave above.



{ "ammenityCards.ammenityItems.ammenityItem": { all: checkedAmenityIDs.join(","), }, },
    Star on GitHub

    Star

    Chat on Discord

    Discord

    online

    Can't find what you're looking for?

    Get dedicated engineering support directly from the Payload team.