Dumb Problem: Find if item is already present in the DB

So this is probably some dumb issue but I can’t get my head around it.

I’m pulling in data into the DB that’s created correctly, so basically, I’m pulling in a bunch of data via API, creating new DB items per item in the API list.

So far so good - I created each item with an ID (from the API)

I’m trying to do this:

  • If an item that matches the same ID is found && created in the last 24hours, then mark this new item as Status ‘new’

Yet when I do this on an ID only basis it works.

When I do this with ID = item's ID & creation date > current date -3 days… it all goes to shit.

Any ideas?

Define “goes to shit” :laughing:

You just need one action: “modify a thing” and you search for the thing with same ID and creation date > current date +days -3.


this example is with different names but has the same concept.

If the thing is found then it’s updated, if it’s not found nothing happens.

I hope this helps :slight_smile:

Cheers

Mariano

That’s my point – This doesn’t work:

The aim is that if it doesn’t find anything, it should create the item.

so, if there is a matching record in the db you need to update it, if there isn’t you need to create it.

Is there a reason why in your search the id is a value but in your create acrion the id is a different value?

It looks like you are researching for an id and creating for a different one

That’s actually the same data, I could put it as id=id on both and it will result in the same case.

Which is that if I’m doing a ID only search, it will find it (multiples… which is normal) but if I add the date, then it will not.

I wonder if I need to do this…

you probably need to share your workflow instead of just bits of it because it’s working if I do this:


so maybe it’s some condition you have in the workflow

I wonder if this is because in your case you have it as the result of step 1 vs a full search.

See I pull in Twitter Data:

This array / list has a bunch of twitter ids.

I then schedule these to create an item:

:point_right: Ideally, this scheduler would only run on the original check, aka if the twitter id if found in the db past yesterday, ignore. If it doesn’t find any id, then add it.

This again, doesn’t seem to work in that logic.

Sooo right now I’m scheduling the task irrespective… (which is not optimal) and then doing the check at the per-id task creation:

the step 1 does a full search anyway, so it’s the same.

It’s still not clear if you have other conditionals or if there is something with the order of execution between the actions and the scheduled workflows.

If the search does not find records when adding the creation date constraint, are you sure you actually have records in the database that can match that search?

Well the constraint is as shown above… there’s nothing more to it.

As for the data, 100% sure it’s there.

This doesn’t work even when I build this manually.

T

Ah, the good old back end “is the data really there” gotcha maybe?

Instead of “Schedule on a List” I would suggest you do a recursive workflow. Save everything to the database, and then iterate through it.

That would be my guess, searches should work, but sometimes when you are doing a load of stuff in the back end on lists Bubble loses track of what it has created and searches stop working.

1 Like

Initially I did that.

I dumped all the follower data to the DB with a status and then ran a separate process to check that item and updated it, but became slow and hogged the DB.

So i moved to spacing out the checking of items via scheduled tasks.

T.

One thing to think about is “order of operations” (actions in workflows don’t actually fire in sequential order in many circumstances) and also being mindful that writes to the database are asynchronous. I can’t see from the screenshots if it is a problem but just something to think about :slight_smile:

There is no harm in reorganising your workflows (with “custom events” , “result of step X” etc) so that the order of operations is very explicit and easy to diagnose. Just a suggestion :slight_smile:

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.