如何插入“引用"?价值进入firestore? [英] How do you insert a "reference" value into firestore?
本文介绍了如何插入“引用"?价值进入firestore?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将文档插入到集合中.我希望文档具有类型 reference
的属性以插入到集合中.但是每次我插入到集合中时,它都会以字符串或对象的形式出现.如何以编程方式插入 reference
类型的值?
I'm trying to insert a document into a collection. I want the document to have a attribute of type reference
to insert into the collection. But every time I insert into the collection, it comes out as a string or an object. How can I programmatically insert a reference
typed value?
绝对可以在 UI 中执行此操作:
It's definitely possible to do it in the UI:
推荐答案
可能最简单的解决方案是将引用键的值设置为 doc(collection/doc_key)
因为需要 DocumentReference
.
Probably the simplest solution is to set the value of a reference key to a doc(collection/doc_key)
because a DocumentReference
is needed.
示例代码:
post = {
content: "content...",
title: "impressive title",
user: db.doc('users/' + user_key),
};
db.collection('posts').add(post)
这篇关于如何插入“引用"?价值进入firestore?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文