Vaffle
Vaffle

Reputation: 107

How would you get a document field?

Firestore db

users
  vaffle
    alias: "Vaffle"
    gemcount: 10

How can I access a document field? What I've tried:

let ref = db.collection("users").doc("vaffle")
this.alias = ref.data().alias

Upvotes: 0

Views: 32

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317948

All you have right now is a reference, which doesn't contain any data. It's just a pointer to a document. You have to query the reference to get the data in the document it refers to:

let ref = db.collection("users").doc("vaffle")
ref.get().then(snapshot => {
    let alias = snapshot.data().alias
})

See the documentation on reading data in Firestore.

Upvotes: 2

Related Questions