Checking if two lists are exactly the same - Vanilla Bubble

Bubble doesn’t have a native list comparison function other then :merge and :intersect operators. There are plugins to achieve it too. But i had a simple need and didn’t want to use a dependency for it. So here is a trick i found useful on some cases. This might not work properly in large lists with over 5K items, but i didn’t test it, maybe it works fine.

Method:

  • get the list (do a search for, or any other method)
  • sort the list by a constant field (creation date, unique id, ect. must be the same on the second list sorting too)
  • then use :format as text operator
    • content to show per list item: this items:unique_id
    • delimiter: comma

At the end of this whole expression use :is not operator and do the same steps for the second list. By this way, we will know if two lists are exactly the same because of sorting and using unique id’s to create a string.

Hope this helps someone, peace!

2 Likes

If the number of items in the merged result is the same as the number of items in the intersection, then the contents of the lists are identical, regardless of sorting. So considering the following expression…

(List1 merged with List2):count is (List1 intersect with List2):count

…if the above is true, then the contents of the lists are identical.

I’ve not done any WU or performance benchmarking of this approach compared to yours, but I do know that Postgres (the DB Bubble uses under the hood) has built-in functionality for working with finite sets; so I would imagine the list merge/intersect operations are pretty efficient.

BTW, a somewhat similar topic came up recently, wihch might be of interest as well.

5 Likes