I am inserting data into a new collection. Once insertion is done I want to get the id of that document and create another collection based on that id. I've tried with my code but it did not work.
here is my code :
const insertData = async() => {
const geocollection = GeoFirestore.collection('home');
try {
await geocollection.add({
title: title,
timestamps: firestore.FieldValue.serverTimestamp(),
name: name,
coordinates: new firebase.firestore.GeoPoint(lat, long),
images: firebase.firestore.FieldValue.arrayUnion(...downloadUrls),
user: user,
status: 0,
}).then(async(e) => {
idx = e.id;
await geocollection.doc(idx)
.set({
menu1title: menu1title,
price1: price1,
image1: image1,
menu2title: menu2title,
});
});
} catch (e) {
console.log(e);
}
};
Edited :
that's how I've resolved that issue , I have replaced
await geocollection.doc(idx)
.set({ ...
by
const db = firestore()
await db.collection("home").doc(idx).collection('menu').doc()
.set({ ....})