Reputation: 449
I want to access UserPrefs and access the weather_location directly without specifying the document name. How can I do that ?
const res = await firestore().collection('Users').doc(uid).collection('userPrefs').doc().set({weather_location: location});
Upvotes: 0
Views: 42
Reputation: 139
You can query the collection UserPrefs and find all the documents that contain a field "weather_location", then update all of them or only one.
something like:
const querySnapshot = await firestore()
.collection('Users')
.doc(uid)
.collection('userPrefs')
.where('weather_location', '>', '')
.get();
const firstDoc = querySnapshot.docs[0];
await firestore()
.collection('Users')
.doc(uid)
.collection('userPrefs')
.doc(firstDoc.id)
.set({weather_location: location});
Upvotes: 1