![](/img/trans.png)
[英]How to write geopoint data in firebase firestore in Flutter?
[英]How to write data to firebase like this format in flutter
如何像這種格式將數據寫入firebase?
qHFij7jKyTa1t9RhkWN2LImqwVl2
是用戶 ID, -MjYl_8EVJJkWcHgn6mJ
是帖子 ID,
我嘗試使用此代碼
await _firestore
.collection('Notifications')
.doc(FirebaseAuth.instance.currentUser!.uid)
.collection(postid)
.doc()
.set({
'userid': FirebaseAuth.instance.currentUser!.uid,
'comment': 'test',
'postid': postid,
'ispost': true,
'time': DateTime.now(),
});
但這不是我想要的。
在我在 Android 的舊項目中,代碼是
ref = ref.getInstance.getReference("Notifications").child(publisherid);
HashMap<String, Object> hashmap = new HashMap<>();
hashmap.put("userid", userid);
hashmap.put("comment", comment);
hashmap.put("postid", postid);
hashmap.put("ispost", true);
hashmap.put("time", DateTime.now());
這種格式怎么能行?
您可以通過以下方式輕松創建子集合。
CollectionReference notifications = FirebaseFirestore.instance.collection('Notifications');
notifications.doc('qHFij7jKyTa1t9RhkWN2LImqwVl2').collection('MjYl_8EVJJkWcHgn6mJ').add({
'comment': 'liked your post',
'isPost': 'true',
});
FirebaseFirestore.instance.collection('通知')
.doc('qHFij7jKyTa1t9RhkWN2LImqwVl2').collection('MjYl_8EVJJkWcHgn6mJ')
.add({ 'comment': '喜歡你的帖子', 'isPost': 'true', });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.