question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Firestore Emulator allowing two documents with same ID.

See original GitHub issue

The firestore emulator is allowing two documents with the same ID to be added in a collection. (I have attached the screenshot).

The original document was imported while starting the emulator. When I tried to fetch the document in my web app (React), the “doc.exists” property was false.

I created a new document with the same ID (keeping the old one there) and it allowed me to create a new document. Also, I was able to fetch the newly created document.

[REQUIRED] Environment info

firebase-tools: 8.6.0

Platform: macOS

[REQUIRED] Test case

Creating two documents in Firestore Emulator with the same ID. One of the documents was imported from a previous export. The other was created on the Emulator UI (on Google Chrome).

[REQUIRED] Steps to reproduce

  1. Start the emulator (new, fresh version).
  2. Create a test document with a specific ID in a collection.
  3. Export the data (using export flag) and close it.
  4. Start the emulator again, but this time importing the previously exported data.
  5. Try fetching (reading) the old document on a web application (doc.exists will be false)
  6. Add a new document in the same collection with the same ID.
  7. Try fetching (reading) the document again, this time it succeeds.

[REQUIRED] Expected behavior

  1. New document with same ID should not be allowed in the same collection.
  2. It should be possible to fetch an already existing document from a previous import.

[REQUIRED] Actual behavior

  1. New document with same ID was created using the Emulator UI.
  2. Old document wasn’t being read (doc.exists = false) on running the “get()” method on a web application. New document was successfully read from the Firestore database once created.
image

firestore-debug.log ui-debug.log

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
MohamedRedcommented, Dec 8, 2020

Hi, My comment has nothing to do with the firebase Emulator.

I just wanted to mention when I create a new document in Cloud Firestore manually using the firebase console with an id ID1, I can then create programatically using the javascript SDK (batch.set) a second document with the same ID1.

I create a document reference to the first document manually created with an auto-generated id ID1. I then batch.set() this document reference with an object. It will then not update the first document manually created, it will instead create a new document with the same id ID1.

1reaction
malcolmdeckcommented, Aug 7, 2020

Sorry for the slow reply - this is being tracked internally as b/163146117

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firestore allows the creation of two separate documents ...
1 Answer 1 · 1 · Well it is not allowed for endusers. · There is absolutely no need to hand-create a document...
Read more >
Connect your app to the Cloud Firestore Emulator - Firebase
Note: It's generally a good practice to use one project ID for all emulator invocations, so the Emulator Suite UI, different product emulators,...
Read more >
Testing security rules | Firestore
Firestore Security Rules include two pieces: A match statement that identifies documents in your database. An allow expression that controls access to those ......
Read more >
Firestore: Copy Data from Prod to Dev or Emulator | by Mathis
This feature also allows you to duplicate data within the same project. ... will be overwritten when they share the same document ID....
Read more >
JavaScript & Firebase - Firestore and Auth - YouTube
In this video, David East is going to show how to use Firestore and Firebase Authentication together to build a secure, real-time, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found