Find specific item in list Firebase

Not exactly. Do not make your list part of the key. Your list "myItemsList should be only in the value. In the key side, use any text as identifier only.

1 Like

Is this how you mean?

My items got replaced with 0, 1, 2…etc
And I am not able to add any new items…
I must have misunderstood you??

This is my DB when do this:

Thanks!

1 Like

We have previously discussed and agreed that no part of the key should be an empty string. Because the last part app variable orderedList is empty the data will overwrite the key above it which is Items.

Make sure none of the parts of the key is empty and the list has at least one element.

Thanks. Im sorry but for some reason I have trouble understanding this one…
This is how I understands it (missunderstand) :slightly_smiling_face::

Now there are no “empty strings” in key session, and the list has at least 1 item. I call myItemsList as the value…

Still this gives me weird results I DB:

Thanks for your help and patience :innocent:

1 Like

Can you explain better what is the issue?

Please note that the scopeVariableInfo is a known issue. I have a workaround but it should not bring you any trouble anyway.

Thanks, yes it was that “scopeVariableInfo” I ment. It looked really weird and that made me think I must have done something wrong…

Well, then it works but there are some things that I am wondering about.

  1. This ordered list comes as a new “session” WITHIN my old list, and I can’t figure out any way to get that to the first and only session other then delete the old one and add a new item from the app and my new “ordered list” will start as a new session in DB. BUT, I can not start my app without anything in there, as you mentioned, it can not be empty. So…how can I do then? Its not a big deal but the address to this list becomes very long…

Screenshot 2021-05-02 at 20.07.47

  1. my DVL is showing these items in the correct order after calling then from the DB (I believe), but it will show the numbers only (0, 1, 2…)
    How can I call the specific item? (in this case, “Is” and “Ost”?

Thanks!!

Hi

Thanks for your help in this!
I got it look a bit cleaner in the DB at last.
But can you see what makes my DB act like this?:

Everything I save in there gets a new line with the newest last which is great, but everything back in the list gets it’s text replaced by a number. Can you see what is causing this?

Screenshot 2021-05-04 at 10.14.00

My attempt here is to:

  • make a list called Items.
  • Save my input-text to a list called myItemsList
  • Then save that “myItemsList” to DB under the current user and inside of that “orderList” called Items.

and it seams to work except for that weird thing, previous items gets replaced by a number as soon as I add anything new…

Thanks!

1 Like

I’m sure you have somewhere in your code a function or a loop to set the value to a text similar to the key.

This is why you have your items as numbers in the list.

Please check and let me know.

Thanks, it was the “get object properties of”-block for the value… remove it and it worked :blush:

1 Like

Hi.
I noticed a problem in my code, and my guess is that it has to do with this block somehow:
Screenshot 2021-05-05 at 10.30.47

But I can not figure out what I should put there otherwise. Thats the only place where I actually take care of what I should do with that text in that field.

So the issue is: Everything seem to work perfectly as how I wish, but as soon as I quit the preview and start the app again everything in the DB gets deleted as soon as I add a new item, then it works fine again, until I quit the app. Logout and in again works though…

Please see video to see more exactly what I mean. (Never mind the DVL list, that’s not taken care of yet and I have only this button active right now, just to really see what it does with my DB).

Could you or some one please advice me in this. How can I do to get that data stay in DB…?

Thanks a lot! :pray:

Here are the code for my button:

1 Like

I guess from your video that you are saving the items in a local file but when you save to Firebase, you do not save the full list (the items in the local file + newly added items) you are saving to Firebase only the newly created items in the list.

Yes, I agree, that’s what it feels like, but I can’t figure out what I should do…
when I click the save button in my app, I will:

  • create a new row in DVL with that input text (this is only to get a fast response feeling in the app)
  • put that input text in a list and sort it to “insert at last”.
  • save this list in DB with the DB.save block.

and as I can see these in the DB console, doesn’t that mean they are saved? Why do they get deleted after restart my app?

I believe I would need some guidance here. Thanks for any ideas or help!

1 Like

If you can see the changes in your Firebase console, then you ARE saving them. So something when you start your app is wiping them out? It’s definitely too easy (I’ve done it!) to wipe out a whole branch of data by accidentally setting the wrong variable, or if for example you have a variable in your path that is set to “”, it can make a real mess.

If you confirm in the Firebase console that your data is getting wiped out specifically when you start up your app, then it might help to write out everything you’re intending to send to Firebase into labels, and look at if you can spot what’s wiping the data.

1 Like

Hi, thanks for your answer. Ill try the label method and see if I can can see anything…
well, its not when starting up it gets wiped out, its when press the “save” button in the app.
So, there MUST be something in that save-block that causing this…

This is my startup-block at the moment:
Screenshot 2021-05-06 at 08.49.21
so, its definitely not that :slightly_smiling_face:

This is my save-block:

There must be here somewhere…

Nothing that you can see at a first sight?

I will try print my steps out on labels later to day…

Thanks!

1 Like

Can you show your firebase data structure also? You’re saving the whole list as one firebase entry as the value of (user id)/items ? That’s going to wipe out anything under items, but maybe there isn’t anything else?

Yes @andreas.sjdtomypv it is in your app. But in a subtle way.

You are saving app variable orderedList to Firebase and this overwrites the existing contents.

You see, when your app starts, you are setting orderedList to empty list and keep adding to it whatever you enter during the app running. Once you save, the content of the list will overwrite what’s in the database. This is logical.

If you want to preserve the existing content in the database you have to create an additional function/routine to start whenever the app starts. This function/routine will load whatever in the database under that specific key to the list (orderedList) so that when you add new entries and decide to save to the database all (old and new) will be saved.

This way you will achieve your goal.

It seems somewhere in your app you are reading the database and getting the contents to show in your list in the screen. It will be wise to add these contents to your app variable orderedList at that time an get it synchronised.

thanks
Well, my thought was to have a structure in DB as user id/Items, where Items are the Items I save, and they will be directly under my user ID. But maybe I should change that structure somehow?

Thanks!
Well, actually I do have this kind of start-block already. I had just removed it just to see what a heck is going on in DB :slightly_smiling_face:. I tried to get it back and also add that orderedList to it. So now it should save the data from DB to that variable. And so that should get it keeping the old items in there as I add new, right?
Well…it’s still something that wipes out all previous items in DB as soon as I add a new one after restart the app.

1 Like

I start to think your on to something here…
the more I think of it…
If I add a list to DB, as the value of user id/Items, and that will, as you say, wipe out everything under Items, then there we got it…? Right?

So, how can I save my list under Items, without wipe anything of what’s already in there? If I add a new step as value the list will be saved in there and that will wipe out everything inside if that value instead, and same goes for if I should remove “Items” and only use “user id”? etc…? There must be some way to not wipe the previous ones??

Thanks for all your help in this! This feels advanced for a newbie as me :grimacing:

1 Like

If you save your list as /some/path/to/items , you’re saying the value of items is that list. If instead you want items to be a bucket that contains item1, item2, item3, and so on, you can’t set items itself to a value. Additionally, if you’re going to want quantities associated with each item, you might want your structure to be more like /some/path/to/items/bananas/ - quantity:1. That leaves room in your data model to later also have a -sku:1234566 and so on.

1 Like