I am trying to convert my firebase implementation which previously used realtime database to use firestore as I like the idea of collections and the perks of using it.
How do I implement below into firestore equivalent?
firebase.database().ref('documentPath').push()
A subcollection is a collection associated with a specific document. Note: You can query across subcollections with the same collection ID by using Collection Group Queries. You can create a subcollection called messages for every room document in your rooms collection: collections_bookmark rooms.
To have the same bahaviour in Cloud Firestore as you have in Firebase Realtime database when using the push()
function, is to let Cloud Firestore auto-generate an ID for you. You can do this by calling add()
function like this:
var addYourDoc = db.collection('documentPath').add({
property_key: 'property_value',
}).then(ref => {
console.log('document ID: ', ref.id);
});
The output in the console will be the actual generated id.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With