Forum Academy Marketplace Showcase Pricing Features

How to automatically create "unique pairs" of users with a Group ID

Hello - So, I’m plugging away at my test project called “Blood Pressure Buddy”. Here’s how it works, a user signs up and is paired with another person trying to lower their BP. they both log their entries and are compared to each other.

Here’s the problem, I’m having. When I new user is created, I need to assign them to a group.

Here’s how I thought about doing it in plain language.

  1. Create a Group ID field with the user.
  2. When user signs up, identify the highest Group ID number that exists for all users.
  3. If the highest Group ID number only returns 1 of that number (meaning that there’s not a complete pair) then give that number to the new user. For example, if there were 2 1s, 2 2s, but 1 3, the next user would get a 3.
  4. If there are 2 of the highest number (i.e. 2 4s) then assign the new user with a group ID of the next highest number, in this case it would be a 5.

This way all the users are getting a unique group ID, but there’s never more than. 2 users with a specific group ID, so you’ll have unique pairs.

The logic for this seems simply, but I can’t find a way in bubble to assign a group ID in this way during the sign up process.

Is there any way to do this in bubble?

If not, any thoughts on how to structure this so I could do this?

Here’s the screen shot of trying to assign a group ID to a new user.


@john3 any thoughts on how to do this? I know you like databases!

What about having a data type of group, with a list field of type user? Then when a user signs up you make a change to a group record, with the item to change being the first item with count of users < 2, with the checkbox set to create such a record if it doesn’t already exist. The change, of course, is to add the new user to the user list for the group.

This sounds like it would work.

Could you tell more a little more specifically about how to implement this in bubble? It’s easy for me to logic through these in plain language, but translating this into bubble language is still hard at the moment.

I would think about it this way …

It seems you want just 1-1 matching ?
If so you have 2 groups, matched and non-matched users.

Create a field called matched_to type list of users on the user table.

In the signup workflow - if matched_to is empty for the current user then search the user table for the first user that matched_to is empty. Add that user to the matched_to list of the current user. Also add the current user to the found users matched_to list. This way you create a unique pair on signup and each will only have one matched user.

If there is no one to match you just have to wait as the next signup will find you as the first non matched pair and you will be matched. So you can leave a message saying waiting for a match on a popup after signup and on their home page.

We me know if that works for you.


Thanks John. That makes sense, I think I need to explore the field type “list”.

I’ll crank away on this tonight and let you know.

As always with Bubble, there will be more than one way to do this, so @john3’s way is another way. For my suggestion, here is some more information.

Like I said, I would create a new data type called Group. It would have two fields -a ‘users’ field, set up like this:

and a ‘user_count’ field:

Then when a user signs up, I would include a Data>Make changes to a thing action. The thing to change would look like something like this:

I hope this helps.

Thanks a lot. This is amazing. I’m grinding on the problem right now, I’ll let you both now how it goes.

@john3 I tried your method, but couldn’t figure out how to write the bubble code. The attached screen shot is as a far as I could get.

I figured out how to identify another user who “matched_to” field is empty that is also not the current user. But I couldn’t figure out two things.

  1. How to then set the match_to field of the current user to the user name of the first user who’s match_to is also empty.

  2. If I figured out item 1, I’m not sure how to also set the match_to for the non-current user to the name of the current user.

@louisadekoya I tried your approach and it worked. See my data below.

My question is, how would I then show the BP data for two unique users, but only if those users are in the same group??

I want to display the data side by side for each user, but only given that they’re paired together.

In order to do this, it seems like I need to create a field for every user that identifies which specific group they are in. This way when I go to display the data, I can user the user data.

For #1 you’re almost there - just add unique_id after :first item and it should be all set. This will add the unique_id of the matching user to the matched_to of the current user. For your second condition I’d also put in unique_id is not current user’s unique_id as I’m not sure if user name is unique or not.

For #2 setup another workflow step after the one above (it has to be after so that the match_to from #1 gets saved in the database). Inside it change the user table. Write matched_to add list Search for Users:first item unique_id (same as above) but in the User conditions put in unique_id = current user’s match_to value also put matched_to is empty just to double check that the user has not be paired previously. This will add the current user’s unique id to the one that you previously matched them with.

So now both will have the unique_id of the user they matched to in match_to. To use it you can just run a search on match_to to display their partner’s stats and progress in a comparison of side by side of data.

Let me know if that works for you.

1 Like

You could create a page/group called BP Readings with a content type of Group and display the current user’s Group in it.

Then add two repeating groups (RGs) to the BP Readings page/group side by side. For the first one, the data source could be Do a Search for BP Readings with constraint: user = current user. For the second it should be Do a Search for BP Readings with constraints: a) user <> current user; b) user is in Parent page/group’s Group’s list of users.

Something like that anyway.