How to query a value from bubble.io using a primary key

I am working on a project and have two data types. One is user and the other one is device details. User is the default data type that bubble gives us. Device details is my custom data type with primary key device id, which is a number. I have another field in device details which stores a date. I want to query this date using the device id primary key to display into a text box.
I have spent 3 days on it and can’t seem to figure it out. Can someone help me?
Thanks in advance.

In Bubble there aren’t Primary Keys (in the way traditional databases use them)…

That said, you can search for things using any field(s)… so you can search for your Device by the field ‘Device ID’ the same as you would any other field.

What exactly are you having trouble with here (it’s not clear from our question)…

Some more details (and screenshots of your app setup) might be helpful.

Hi Adam,
Thanks for the reply.


This is how Device Details table is structured. I want to check for each device’s subscription end date. Given that I only know the device id.

What exactly do you mean by “I want to check for each device’s subscription end date.”?

What are you trying to do?

In any case, just search do a search for the Device by its Device ID - then you can use that data however you want.

If I have understood you correctly…
You want to look up the database via foreign key, not a data field from this db?
If that is correct - you can’t do it. Tried it. Doesn’t work.
You can only search it via do a search for in the app itself, not via database view in bubble.io.

If this is critical - you can make a workflow which copies the foreign key to this db in one of fields or slug. Some workaround.

Hi Michal,
I tried “do a search for” option, but I do not see a way to access the subscription end date even if I search for a specific device id.
Thank you for the suggestion.

It’s simple:

search for devices: first item's subscription end date

1 Like

Hi Adam,
Thanks for your reply.
Instead of just looking for the first item’s subscription end date, I want to do something like this:

search for devices: specific device id’s subscription end date

Instead of just looking for the first item’s subscription end date, I want to do something like this:

search for devices: specific device id’s subscription end date

Yes… I know what you’re trying to do…

That’s how you do it…

search for devices: first item's subscription end date

A search always returns a list - that list may contain many items or just 1 (or even none) - but it’s always a list.

So if you’re searching for something by a unique Identifier (in your case the Device ID), where there is only one matching item in the database, the returned list will contain a single item.

But you need the Item - not the list.

So you need to specify which item from that list you want to use - to do that you need to add :first item to extract the individual thing from the returned list.

(you could also use :last item or :random item - as there is only one item in the list they all do the same thing)

So, as I already said… you just need to use:

search for devices: first item's subscription end date

(where, obviously, your searching for the specific thing using the Device ID as a constraint)

3 Likes

Hi Adam,
Thank you for your help. I finally figured it out.
I had to do a search for device details, then apply a filter and in the filter I had to mention deviceid = whatever device id I want to get the subscription end date for, this will give us a list as a result, which only has 1 item and then we can get the first item’s subscription end date.

1 Like