Skip to content

Detecting when a document does not exists in Firestore #158

Answered by fenix-hub
Gegbee asked this question in Q&A
Discussion options

You must be logged in to vote

Error 404 is itself the way to know if a document exists or not.
If a document does not exist on a .get() request, some signals will be emitted:

  • error(body_error : Dictionary) and task_finished(body_error : Dictionary) from a FirestoreTask
  • error(body_error : Dictionary) from a Firestore
    Just connect those signals to a function, and if you get the error concerning a document it does not exist.

If you actually want to only check the existence of a document without retrieving its data, there is no way I'm aware of.
The only way would be to create a Document that stores the ids of all the other documents you are using, and then get the content of that document to check if an id exists.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Gegbee
Comment options

Answer selected by fenix-hub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants