freetrade-io / ts-firebase-driver-testing

Swap out Firebase as a driver for in-process testing
MIT License
11 stars 1 forks source link

Implement get() using FieldPath for DocumentSnapshot #106

Closed DainisGorbunovs closed 3 years ago

DainisGorbunovs commented 3 years ago

Currently the data can be read from DocumentSnapshot using .data().

const snapshot = await firestore().collection('example').doc('document').get()
const data = snapshot.data()
const fieldValue = data?.fieldWeWant?.deeperField

However, sometimes it's easier to use a field path in order to read a specific field. This PR implements get() on DocumentSnapshot objects for such cases.

const snapshot = await firestore().collection('example').doc('document').get()
const fieldPath = 'fieldWeWant.deeperField'
const fieldValue = snapshot.get(fieldPath)