您如何插入“参考”重视火焰?
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?
It's definitely possible to do it in the UI:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
最简单的解决方案可能是将参考键的值设置为
doc(collection/doc_key)
,因为需要documentRereference
。示例代码:
Probably the simplest solution is to set the value of a reference key to a
doc(collection/doc_key)
because aDocumentReference
is needed.Example code:
我今天试图弄清楚这一点,而我提出的解决方案是使用
.doc()
创建一个doc参考,这将存储a documentReference 在
property
字段上键入字段,因此在阅读数据时,您将能够访问该数据文件如此I was trying to figure this out today and the solution I came to was to use the
.doc()
to create a doc referenceThis will store a DocumentReference type on the
property
field so when reading the data you will be able to access the document as so这是存储在Firestore的模型类。
我需要用参考值存储Flightleg对象。为了做到这一点:
可以将对象保存的服务用引用另一个对象到firestore中:
This is the model class to store in firestore.
I need to store FlightLeg object with reference value. In order to do this:
The service which can save the object with referenced to another object into firestore:
该字段的值必须为类型 。看来您正在将一些其他对象放在其中,其中包含一个名为
id
的属性,这是一个字符串。The value of the field must be of type
DocumentReference
. It looks like you're putting some other object in there that has a property calledid
that's a string.似乎最近可能有一个更新使上述答案现在已经过时了。有趣的是,现在的解决方案甚至更容易。他们已删除了.REF选项,但是REF现在自动获得。
因此,您可以这样做:
成员是DOC参考的位置,很简单。 (忽略这3大声笑。)
It seems there may have been a recent update that has made the above answers outdated now. Funnily enough, the solution is even easier now. They've removed the .ref option, but the ref is automatically gotten now.
So you can just do:
Where member is the doc reference, simple as that. (Ignore the this3 lol.)