簡體   English   中英

firestore firebase 問題:如何在不指定文檔名稱的情況下更新文檔

[英]firestore firebase problem: how to update the document without specifying the name of the document

在此處輸入圖像描述

我想訪問 UserPrefs 並直接訪問 weather_location 而不指定文檔名稱。 我怎樣才能做到這一點?

const res = await firestore().collection('Users').doc(uid).collection('userPrefs').doc().set({weather_location: location});

您可以查詢集合 UserPrefs 並找到包含字段“weather_location”的所有文檔,然后更新所有文檔或僅更新一個。

就像是:

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});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM