Firstly, we have users collection and contacts is sub-collection of users.
Now, set data for contact with users/userid1/contacts/contactid1 path, and do not set data for user with users/userid1 path.
Get contact by firestore().collection("users").doc("userid1").collection("contacts").doc("contactid1").get() will return existence data.
But get firestore().collection("users").doc("userid1").get() return undefined.
If we try to gather documents of users collection by query or get all, undefined document could be ignored.
Firstly, we have
users
collection andcontacts
is sub-collection ofusers
. Now, set data for contact withusers/userid1/contacts/contactid1
path, and do not set data for user withusers/userid1
path.Get contact by
firestore().collection("users").doc("userid1").collection("contacts").doc("contactid1").get()
will return existence data. But getfirestore().collection("users").doc("userid1").get()
returnundefined
. If we try to gather documents of users collection by query or get all,undefined
document could be ignored.Sometimes, it doesn't need to set data for document, so it should be set as empty. Like this:
firestore().collection("users").doc("userid1").set({})