Is faunaDB support trigger by data change/add in any collection?

Hello Guys!

Do you have any idea? How we can trigger on data change/add in any collection.

Same like firebase trigger?

or any alternate way to achieve like this.

What I want to do?

I’ve two collection

users
user_address

Once any new user is register, I want to check if already have user from that specific address or not?
if yes, than simply increment counter by 1.

One way of doing this is through the streams API. So your client will subscribe to the event, and you can fire another data update.

Thanks @Shadid for the solution.
But as I know, streaming is quite expensive with Fauna

and I think solution is something like,
on set document we have to set the streaming in which can I trigger the event.

I see, good feedback. I’ll take this to the product team. A good workaround would be to unsubscribe from streams when not needed.

We have an open feature request for webhooks. Take a look at that, and if that is what you are looking for, then make sure to vote for it, and I encourage you to add your use case there as well.

That said, it sounds like all of the work that you want triggered is inside of the database. If that is the case, then you can use ABAC to only allow users to change/add to the collections through UDFs.

Firebase triggers require you to make extra networking trips in and out of the db. Fauna lets you run logic in the database within a single transaction. If there is an error at some point in the query, then the whole thing rolls back, ensuring your data remains consistent.

CreateRole({ 
  name: "RegisterUserFn", 
  privileges: [
    /* All of the things that the function needs */
  ]
})
CreateFunction({
  name: "RegisterUser",
  role: Role("RegisterUserFn"),
  body: Query(
    Lamba(
      ["email", "password", "address"],
      Let(
        {
          user: Create(Collection("users"), {
            data: { email: Var("email") },
            credentials: { password: Var("password") }
          }),
          // Do stuff with address
        },
        {
          // return some payload
        }
      )
    )
  )
})
CreateRole({ 
  name: "PublicRole", 
  privileges: [
    {
      resource: Function("RegisterUser"),
      actions: { call: true }
    }
  ]
})

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.