# Firestore: “6 ALREADY_EXISTS: Document already exists”

> Firestore returns ALREADY_EXISTS when create() writes to an ID that is taken. Use set() to overwrite or merge, add() for a new ID, or handle the error.

Canonical: https://app369.com/fix/firestore-already-exists-document/
Last updated: 2026-11-09

ALREADY_EXISTS is a Firestore error, gRPC code 6, for a create() call on a document ID that is already taken. The message ends with the full document path. create() only writes new documents, so the write fails. Use set() to overwrite or merge, add() for a fresh ID, or keep create() and handle the error.

**Short answer**

Decide what should happen when the document exists. To replace it, use set(). To change some fields and keep the rest, use set() with merge: true. For a new document every time, use add() or doc() with no ID. If the document must not be overwritten, keep create() and treat code 6 as “already done”.

Rather not fix it yourself? [**App Fix Ticket**](https://app369.com/fixed-price/flutter-firebase-bug-fix/) starts with a fixed-price diagnosis, then a fixed price for the fix before any fix work.

## **Why the document exists, and the fix**

1. 01 ### **create() only writes new documents**
  > “Create a document with the provided object values. This will fail the write if a document exists at its location.” [**Google Cloud Node.js client, DocumentReference.create()**](https://googleapis.dev/nodejs/firestore/latest/DocumentReference.html) In the Admin SDK, create() fails when the ID is taken, on purpose. batch.create() and transaction.create() work the same way.
2. 02 ### **You meant to overwrite or merge**
  > “If the document does exist, its contents will be overwritten with the newly provided data” [**Firebase, Add data**](https://firebase.google.com/docs/firestore/manage-data/add-data) set() creates the document if it is missing and replaces it if it exists. Add merge: true to keep fields you don’t send.```
await db.doc(\`users/${uid}\`).set({ plan: 'pro' }, { merge: true });
```
3. 03 ### **A retry ran after the first write worked** A function that retries after a timeout can run create() twice. The first one wrote the document, so the second fails. Treat code 6 as success when the document is the one you meant to write.```
try {
  await ref.create(data);
} catch (err) {
  if ((err as { code?: number }).code !== 6) throw err; // 6 = ALREADY_EXISTS
}
```
4. 04 ### **The ID isn’t as unique as it looks** IDs built from an email, a date or a name can repeat. Use add() or doc() with no ID for a random one, or keep the natural ID and expect the error.

Checked against the vendor’s docs on November 9, 2026: [Google Cloud: Firestore Node.js DocumentReference](https://googleapis.dev/nodejs/firestore/latest/DocumentReference.html); [Firebase docs: Add data to Cloud Firestore](https://firebase.google.com/docs/firestore/manage-data/add-data).

## **Rather hand it over?**

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

- [from $450**App Fix Ticket**One reproducible bug in an existing mobile or web app, diagnosed and fixed.**See scope and start**](https://app369.com/fixed-price/flutter-firebase-bug-fix/)
- [from $450**AI-Built App Rescue**A Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.****No issues worth fixing, no charge.**** If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.**See scope and start**](https://app369.com/fixed-price/ai-app-rescue/)

[**All 127 Fiverr reviews**](https://app369.com/reviews/)

Related: [**Firestore transaction too big**](https://app369.com/fix/firestore-transaction-too-big/) · [**Firestore unsupported field value: undefined**](https://app369.com/fix/firestore-unsupported-field-value-undefined/) · [**Firestore query requires an index**](https://app369.com/fix/firestore-query-requires-an-index/) · [**Firebase “Missing or insufficient permissions”**](https://app369.com/fix/firebase-missing-or-insufficient-permissions/)

Questions

## **More on this error**

<details>

<summary>**Does the web SDK have create()? **+</summary>

No. The client SDKs use setDoc and addDoc, which don’t raise this error. ALREADY_EXISTS comes from the server SDKs, such as the Admin SDK in Cloud Functions.

</details>

<details>

<summary>**Is set() safe if two writes race? **+</summary>

The last write wins. If exactly one writer should win, use create() and handle code 6, or a transaction.

</details>

<details>

<summary>**Can you fix it for me? **+</summary>

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

</details>

A different error?

## **Describe it and get a written quote**

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.

[**Describe your problem **→](https://app369.com/contact/) [**All fixes**](https://app369.com/fix/)