How do I conditionally query items inside an array?

default discord avatar
acemaker00
4 weeks 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(","), }, },
    Open the post
    Continue the discussion in Discord
    Like what we're doing?
    Star us on GitHub!

    Star

    Connect with the Payload Community on Discord

    Discord

    online

    Can't find what you're looking for?

    Get help straight from the Payload team with an Enterprise License.