[英]How to create a collection inside a document in Firestore with Flutter?
[英]How to create a collection inside a document?
我正在使用 Firebase 編寫 Flutter 應用程序。 創建用戶時,我正在做:
Firestore.instance.collection('users').document(user.uid).setData({
'name': name + ' ' + surname,
'email': user.email,
'registerDate' : DateTime.now(),
'isEmailVerified': user.isEmailVerified,
'location': location,
'photoUrl': user.photoUrl,
'votes' : {},
});
我希望“投票”成為一個集合並包含文檔。
如何在文檔中創建集合?
如果您的uid
文檔下需要包含投票的子集合,請使用以下代碼行:
Firestore.instance.collection('users').document(user.uid)
.collection('votes').document(vote)
.setData({/* ... */});
其中, vote
是一個對象,它被添加到了votes
子集合下。
如果你想添加之后添加的用戶到收集users
收集,再檢查時, setData()
操作完成,並且寫了之后vote
對象上面的參考。
要記住的另一件事是,在 Cloud Firestore 中,文檔和子集合不像文件系統文件和目錄那樣工作。 另請參閱我在以下帖子中的回答:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.