1
votes

So I have a database in Cloud Firestore which I am querying from a React app (created with create-react-app). The original developer has named the fields of a collection that start with a number. Example:

collection: users
document: Firebase generated ID (1P3clkdlk409C)
field: 2_score

So when I go to query this from react:

db.collection('users').get().then(querySnapshot => {
querySnapshot.forEach(doc => {
console.log(doc.data().2_score
})})

This doesn't work because react 'sees' the number as not part of the function.

Thanks for any help or guidance you can give!

1
can you use bracket notation? ['2_score'] - imjared

1 Answers

2
votes

You should use the square brackets notation, as follows:

console.log(doc.data()['2_score']);