Now i can able to get doc id and insert data into DriversCurrentBookings. When new currenUserRequest doc id is added in collection db, it should update in realtime in firebase (using cloud firestore)
Here is the code used:
var citiesRef = db.collection('UsersBookingRequest');
var allCities = citiesRef.get()
.then(snapshot => {
snapshot.forEach(doc => {
console.log(doc.id, '=>', doc.data());
var reqID = doc.data().UID;
var cityRef = db.collection('UsersBookingRequest').doc(reqID);
var getDoc = cityRef.get()
.then(doc => {
if (!doc.exists) {
console.log('No such document!');
} else {
console.log('Document data:', doc.data());
lat = doc.data().Currentlat;
long = doc.data().Currentlong;
UID = doc.data().UID;
// token = doc.data().token;
address = doc.data().address;
date = doc.data().date;
time = doc.data().time;
console.log(lat);
console.log(long);
console.log(UID);
// console.log(token);
console.log(address);
console.log(date);
console.log(time);
var data = {
lat: lat,
long: long,
UID: UID,
address: address,
date: date,
time: time
// token: token
};
// Add a new document in collection "cities" with ID 'LA'
var setDoc =
db.collection('DriversCurrentBookings').doc(doc.data().UID).set(data);
}
})
.catch(err => {
console.log('Error getting document', err);
});
})
})
.catch(err => {
console.log('Error getting documents', err);
});