Firestore Create/Update upsert into subcollection

I’m new to n8n… what am I doing wrong here? Is this a bug or not supported?

When my workflow executes a document is created in my subcollection (users/{user-id}/videoAskQuestions) with an id of undefined even though it appears as though it should work see screenshots:

this is in Firestore:

Hi @benneic, welcome to the community! I hope you’re having a good day thus far?

In the update key field you’d define the name of the field which holds the id of the document to update (or create). So in your example, n8n would use a field with a name of 02266c88... which does not exist (and thus would have an undefined value).

Instead you’d need the name of the field with the respective value:

Example workflow
{
  "nodes": [
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "message",
              "value": "={{new Date().toISOString()}}"
            },
            {
              "name": "id",
              "value": "={{(+new Date).toString(36).slice(-5) + Math.random().toString(36).substr(2, 5)}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "operation": "upsert",
        "projectId": "mutedjam-app-n8n-cloud",
        "collection": "my_collection",
        "updateKey": "id",
        "columns": "message"
      },
      "name": "Google Cloud Firestore",
      "type": "n8n-nodes-base.googleFirebaseCloudFirestore",
      "typeVersion": 1,
      "position": [
        650,
        300
      ],
      "credentials": {
        "googleFirebaseCloudFirestoreOAuth2Api": {
          "id": "36",
          "name": "Google Firebase Cloud Firestore account"
        }
      }
    }
  ],
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "Google Cloud Firestore",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

I hope this makes sense and helps! Let me know if you still run into any trouble afterwards.

Awesome, that works now! And obvious what *Update Key * means now that I’ve had a sleep and come back to it…

Update Key = “Provide the key that corresponds to the value in the input used to identify the document for create and update operations.”

Cheers!

1 Like