c# - 如何在 c# 上将子集合添加到 firestore?
问题描述
我正在尝试在 firestore 上的 c# 上的文档中添加子集合,但在 firestore 的文档页面中找不到它?
我是firestore和nosql的新手,很多这些东西对我来说仍然很复杂。
解决方案
您只需在子集合中创建一个文档 - 集合本身不是您需要创建的实体。
所以如果你已经有一个DocumentReference
for 的东西,你可以使用:
DocumentReference topDoc = ...;
CollectionReference subCollection = topDoc.Collection("subcollection");
DocumentReference subDoc = await subCollection.AddAsync(new { Name = "Jon", Score = 10 });
或者,如果您想指定一个 ID,请创建一个新 ID,DocumentReference
然后从中创建文档:
DocumentReference topDoc = ...;
CollectionReference subCollection = topDoc.Collection("subcollection");
DocumentReference subDoc = subCollection.Document("subdoc");
await subDoc.CreateAsync(new { Name = "Jon", Score = 10 });
推荐阅读
- reactjs - 使用 react 启动项目失败
- vb.net - 传递列表作为参数
- python - 将限制作为斐波那契数列的参数并在 Python3 中打印到该限制的函数
- reactjs - 如何获取功能组件中的当前状态值?
- c# - HtmlEncode 列表
在 MVC 中 - python - Matplotlib 的 Animation.save 生成无法打开的 png
- java - 尝试从指针读取字节数组时,JNA 无效的内存访问
- vue.js - Vue + Eslint:lintOnSave=false 不起作用,浏览器覆盖仍然会中断开发
- javascript - HackerRank - 最小交换 2 超时
- javascript - 使用 puppeteer 在 page.waitForFunction() 中传递一个函数