Reputation: 1591
I am trying to test whether a document exists with title uid. I have confirmed that the document exists in Firestore within the users collection, but doc.exists always returns false. Note that my document uid contains only collections (no fields).
firebase.auth().onAuthStateChanged((user) => {
if (user) {
// User is signed in.
var uid = user.uid
db.collection("users").doc(uid)
.get()
.then((doc) => {
console.log(doc)
if (doc.exists) {
console.log('returning user')
} else {
console.log('new user')
}
}).catch(function(error) {
console.log("Error getting document:", error);
});
} else {
// User is signed out.
// ...
}
Upvotes: 3
Views: 2343
Reputation: 1591
This happens because while you had created collections within the document, you never created the document itself. You can tell whether documents exist because if they dont they will show up in Firestore as italics.
Upvotes: 13