Weardian
Weardian

Reputation: 221

Firebase firestore.doc not returning data

When I try to query a document that I've set up using the firebase console I don't get anything back that looks like the data I've entered.

I've tried console logging the collection as well but get nothing back from that either. I've checked that the firebase config is correct but it seems fine.

let doc = firebase.firestore().doc(`users/${this.userId}`)
    console.log('doc', doc)

In trying to console.log the document I get the following response

console.log

I was expecting the collection or just the document to appear in the console log with all the data from firestore.

Upvotes: 0

Views: 2443

Answers (1)

ersin-ertan
ersin-ertan

Reputation: 2301

There are three concepts to know here:

  1. Documents a lightweight record that contains fields, which map to values
  2. References Every document in Cloud Firestore is uniquely identified by its location within the database.
  3. The data which is the content of a single document, retrieved using .data()

let docRef = db.collection("objects").doc("singleObjectWithDataFields") is the reference.

docRef.get().then(function(doc){ returns the document

doc.data() returns the data fields, which map either to values, or to maps which are complex nested objects

Upvotes: 2

Related Questions