[英]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.