Search for Duplicate Data using Dictionary Blocks

I have a Firebase data set that houses user data (Name, Address, Phone). My app allows new users to add their own data to the database.

Data Structure looks like this:

.....John Smith
.....Steve Clark
..........Steve Clark
..........2019 Main Street
..........Red Baron
.....Mary Jones

2 searches I am wanting to accomplish are is there already a 'Steve Clark' and is there already a 'Red Baron' in the database. If user 'Steve Clark' already exists I can notify the user that name is already in use, as well as the chosen nickname of 'Red Baron'. Those fields need to be unique.


I think because I have nested loops that the Dictionary blocks are the way to go but I guess I dont understand them yet. I need to be able to 'walk' through the keys of all the users to see if there are duplicates.

No need to get all user data to local.
just use GetValue
set tag as 'Users/SteveClark'

If you got a value, the user exists, otherwise, not exist.

I may have spoken too soon .. I thought it worked when I first looked at it but I see some issues. I understand what the block does and the logic would be perfect.

One 'new' issue I have is I am already using a GetValue tag elsewhere in my app so I will need to be very creative with the TAG and VALUE from the GotValue blocks after the GetValue runs .. or can I add a second FirebaseDB and configure it with the same values as DB1?

Why doesnt this work for me? Is there a better way? The GetValue method is going to be a struggle considering I am already using that block for something else..


before you can the getValue, you set variable to 1 or 2, and when got value you check if variable is 1, then .... else if variable is 2, then ...

I deal with this by adding extra single-purpose FireBaseDB components named after their different purposes, like FireBaseDBCheckUserExists.

That lets me squirrel away the duplicate user checking into that component's GotData event, away from other processing.

There is a slight price to be paid in cluttering up the Designer component collection.

I think I understand what you guys are saying .. something like this?

Only in my case, I never see the ShowMessageDialog and I can confirm that the user name is already in the database..

The only thing I can think of is my understanding of what the Value is when I GetValue must be wrong, so it never triggers...

Where did you set the login variable?
You need to set it every time you get value.

1 Like

I set the LOGIN variable to "Login" when user presses the Login button and to "NewUser" when the user presses the button to create new accts.. those happen at the beginning of the app.

I am not sure I understand what you mean by "FireBaseDBCheckUserExists." Is there an existing routine/block that can do this for me? I would not mind the extra clutter in the Designer if there is, I am already having issues making mine work.

Go into the Designer and locate your FireBaseDB1 component.
Click on it to select it, then hit Ctrl-C on your keyboard.
Then hit Ctrl-V.
That will give you a second one, which you can rename in the Designer and use as you see fit.
Watch for the events that got copied along with the component.

P.S. Here is an example of using this technique, from an obsolete sample based on the dead Fusion Tables component:

Notice the components ftbAvailable, ftbUpdate, ftbInsert components.

Instead of using a second Database, I opted for the If\Then method in the GotValue blocks. If "New User" then do these things. If "Existing User" then do these things.. works just fine for me.

I did solve my issue of looking for duplicate user names using this method

Duplicate User

I perfome a GetTagList to populate the 'global allUsers' list and it works, I dont know why I had so much trouble before.

I am now stuck on the second part, I am trying to search for duplicates of a different field, located deeper in my database and cant figure it out yet..

I have tried these two methods but they only give me a list of the Keys and not the Values..

App Inventor Dictionary

My databse structure looks like this..

I am wanting to search the ChatName field. The issues is the name of the Key is different for each user (its their username) so I cant hard code that. Since there are multiple users I figure the List By Walking Key Path is the best way to go, but I still only get Key and not a complete pair with the Value. Any pointers?

I see three different approaches to this, depending on the scale of the app and your taste for non-block approaches.

  • Grab Everything into a dictionary and traverse the resulting dictionary in a For Each Key and Value in Dictionary loop, searching as you go
  • Add a new branch ChatNames to your DB, with User Names under the ChatNames, and do double maintenance
  • Venture into the advanced world of FireBase Indices

Firebase Indices .. never heard of them but lucky for me I have the time to look them up. Thanks for the hint.

Like this ?


If I understand this correctly, ListPicker requires a manual selection of the desired choice, yes? I am needed something automated for when a new user is creating an account. Something that will check to see if their choice of Chat Names is already in use or not .. so I dont think this solution will work for me.

OK, sorry, didn't read the entire thread to grab that important piece of information!

What the Firebase developers usually recommend, when wanting to easily get at "buried values", it to make a separate list of these values under a different node, e.g. ChatNames, then all you have to do is return a taglist of those entries, and check the proposed chatname against the list.

This separate list is "as well as", not "instead of" what you already store for the user.

I like this idea. It would not be much trouble for me to create a seperate list for the Chat Names .. and certainly would be easy to use. I am going to give this a shot.

OK so I have a new list for chat names in the database and it saves the data the way I want just fine. But I now have an issue that I suspect has to do with the Get Tags block.

I can perform the first GetTags and it populates my user list just fine, I can check for duplicate users just fine and everyone is happy.

When I execute the second GetTags to populate the chat names list, thats when things get crazy and broken.

Does the execution of a GetTags affect anything else when they are run? Can I run them more than once? I am trying to populate two different lists with two different sets of tags using an If - Then block .. if variable = 1 then set bucket to "Users", and then GetTag. If variable = 2 then set bucket to "ChatNames" and then GetTag but that doesnt seem to work?

Are you also using if/else conditions with your variables in the GOT Taglist event ?