javascript - 相当于Firestore中的.push?
问题描述
我正在尝试将以前使用实时数据库的 firebase 实现转换为使用 firestore,因为我喜欢集合的想法和使用它的好处。
如何在以下等效于 Firestore 中实施?
firebase.database().ref('documentPath').push()
解决方案
使用该功能时,在 Cloud Firestore 中具有与在 Firebase 实时数据库中相同的行为push()
,就是让 Cloud Firestore 为您自动生成一个 ID。你可以通过调用这样的add()
函数来做到这一点:
var addYourDoc = db.collection('documentPath').add({
property_key: 'property_value',
}).then(ref => {
console.log('document ID: ', ref.id);
});
控制台中的输出将是实际生成的 id。
推荐阅读
- dart - 动画小部件推送其他小部件
- python - 拟合曲线时如何修复“TypeError:f() 需要 3 个位置参数时给出 4 个错误”
- html - 当元素包含长文本时,如何强制伪“后”元素的宽度?
- javascript - 如何遍历对象数组并过滤掉同一小时内的项目
- ios - 在某些操作系统版本中未调用 WKHTTPCookieStore getAllCookies 完成处理程序
- c# - 如何在 WPF 中的窗口之间导航?(不是浏览器)
- sql - 如何从子查询中获取两个值用于sql的where子句
- algorithm - 图灵机元素区别问题
- javascript - 为什么单击提交时我的表单未验证
- java - 当 'Categories 等于 null 时跳过循环的第一个循环