Firebase DocumentSnapshot fields

Viewed 167

So my head is slowly understanding the Firebase docs, and I think I know understand the Document Snapshot as seen here: https://firebase.google.com/docs/reference/js/firebase.firestore.DocumentSnapshot.

But when I log the snapshot, it looks like this

t {
_delegate: e {_firestore: e, _userDataWriter: e, _key: t, _document: t, _converter: null, …}
_firestore: t {_delegate: e, Jc: t, INTERNAL: {…}, Yc: FirebaseAppImpl}
exists: (...) // expected
id: (...) // expected
metadata: (...) // expected
ref: (...) // expected
}

I have tried googling, but I cannot seem to find out what _delagate or _ firestore do or reference. My brain is telling me that they are part of what creates the snapshot, and not to worry about them, but my curiosity is piquing.

If anyone has a simple high lever explanation, that would be appreciated.

1 Answers

When you log the DocumentSnapshot object, you also see its internals. Instead of trying to make sense of those, I recommend sticking to the public API as defined by the documentation you linked.

So if you want to see the data of the document, console.log(doc.data()). If you wanna see the document ID, console.log(doc.id), etc.


If you really want to learn more about the internals of the object, the entire SDK is open-sourced, so this export class DocumentSnapshot... would be a good starting point there

Related