我正在尝试将以前使用实时数据库的 firebase 实现转换为使用 firestore,因为我喜欢集合的想法以及使用它的好处。
我如何将以下内容实现为 firestore 等效项?
firebase.database().ref('documentPath').push()
使用 Cloud Firestore 时,要具有与 Firebase Realtime 数据库中相同的行为push()
功能,就是让Cloud Firestore自动为你生成一个ID。您可以通过致电来做到这一点add()
像这样的函数:
var addYourDoc = db.collection('documentPath').add({
property_key: 'property_value',
}).then(ref => {
console.log('document ID: ', ref.id);
});
控制台中的输出将是实际生成的 id。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)