Contended transaction

Hello everyone,

I see there is a similar post from last year here, related but not equal, that why I’m opening a new thread.

I have a sync task job that send messages to a specific conversation in our app according to some events triggered by an event listener.
As the title of this post, this is the error I’m getting when sending messages, even only sending 1 message. (sometimes yes, sometimes no).
I use the same function for the chat app we are building, and it works.
It’s just a duplicate function that send messages on behalf of the admin.

In the related post the problem came due to an index, but in my case I’m not using an index, as you can see below, I’m creating a new document and updating 1 at time.

conversationRef: Ref(Collection("conversations"), Var("id")),
            messageDoc: If(Exists(Var("conversationRef")),
              Create(Collection("messages"), {
                data: {
                  conversation: Var("conversationRef"),
                  content: Select("message", Var("data")),
                  type: Select("type", Var("data")),
                  sentOn: ToTime(Select("eventTime", Var("data"), Now())),
                  author: Ref(Collection("users"), 0),
              }), Abort("Conversation ref not found")),
            updatedConversationDoc: Update(Var("conversationRef"), {
              data: {
                latestMessage: Select(["ref", "id"], Var("messageDoc")),

The error looks like this:
responseRaw: '{"errors":[{"ref":{"@ref":{"id":"311798847832591111","collection":{"@ref":{"id":"conversations","collection":{"@ref":{"id":"collections"}}}}}},"code":"contended transaction","description":"Transaction was aborted due to detection of concurrent modification."}]}

The conversation exists, and I can send messages to it.

What could be the cause of this error here?

Thank you very much.

Hi @3rChuss,

Just to cover all the bases, what indexes do you have defined on Collection("conversations") and Collection("messages")? If either of them have a unique index set on them that might be causing the issue. Even if you’re not using an index in this query, any indexes on those collections would need to be updated when either the Create() or Update() queries are run.

You can check the settings for those two individual indexes in the dashboard. Or, you can quickly get a list of your unique indexes with this FQL snippet:

    Equals(true, Select("unique", Get(Var("i")),false)),


1 Like

Thanks Cory.

That is really helpful.

I have updated the indexes.

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