Help with complicated query: Can I loop through a Things list and “Do a search for…” for each... and then merge it all together?

Hello! I am working on a somewhat nuanced and tricky database query and wondering (a) if it’s possible in Bubble, and (b) how to approach it.


  • Users have many “Songs” (via a user-song join table).
  • Users can create a “Playlist” which can also contain many songs (via a setlist-song join table)
  • Each “Playlist” has a list of Users (let’s call this list the “Contributors”) that are able to contribute their “Songs” to it. “Contributors” are stored in a “Thing, is a List” field of the “Playlist” (althoguh I am not married to this schema)
  • “Contributors” owned songs are added, up to a “Max Songs” limit, based on their subscription tier.

I want any “Contributor” to be able to look at a given “Playlist” and see the full aggregated list of “Songs” from each user with consideration for their respective “Max Songs” limit. End result is a list that encompasses all the songs across all the Editors, BUT limit each “Contributor’s” list of songs individually by their own “Max Songs” permission.

Sally has 5 songs, with a max songs permission of 10
Bob has 15 songs, with a max songs permission of 10
Jimbo has 22 songs, with a max songs permission of 20
Mary has 27 songs, with a max songs permission of 30

The resulting list would return 5 songs from Sally, 10 songs from Bob, 20 songs from Jimbo, and 27 songs from Mary. All in the same list.

… this query would be easy were it not for the “Max Songs” limit… but this is really important to my application. I basically need to loop through the “Contributor” list and “Do a search for…” for each… is this possible? Is there a more efficient way?

Help! Thanks in advance!

My thought is to do something like this:

Have an additional field on the song where we will keep track of if it’s one of their “CHOSEN_SONGS” So if their MAXSONGS is 20 and they have 22 songs, only 20 of those will have “CHOSEN_SONGS = TRUE” and the extras are not. (The user can change their Chosen Songs, but can never have more than Max Songs.)

This way on the Search you can just filter where Chosen_Songs = True.

This would make the search super easy, but require you to make some additional things so the User can switch their chosen songs, and songs uploaded after “MaxSongs” will have to default to Not a Chosen Song.

Maybe this isn’t what you’re describing, but it’s what comes to mind. Hope this helps.