相当于 Firestore 中的 .push ?

Joj*_*rte 6 javascript firebase google-cloud-firestore

我正在尝试将以前使用实时数据库的 firebase 实现转换为使用 firestore,因为我喜欢集合的想法和使用它的好处。

我如何在下面实现 Firestore 等价物?

firebase.database().ref('documentPath').push()
Run Code Online (Sandbox Code Playgroud)

Ale*_*amo 11

使用该push()功能时,要在 Cloud Firestore 中拥有与在 Firebase 实时数据库中相同的行为,就是让 Cloud Firestore 为您自动生成一个 ID。你可以通过调用这样的add()函数来做到这一点:

var addYourDoc = db.collection('documentPath').add({
  property_key: 'property_value',
}).then(ref => {
  console.log('document ID: ', ref.id);
});
Run Code Online (Sandbox Code Playgroud)

控制台中的输出将是实际生成的 id。