I would like to copy the email associated to each user to a Firestore collection ('users') using Cloud Functions. Each document in the collection has the UID of the user as its name.. I have the following function:
const getAllUsers = (req, res) => {
auth.listUsers().then((userRecords) => {
userRecords.users.forEach(
(user) => db.collection('users').doc(user.uid).update({ "email": user.email })
)
res.end('Retrieved users list successfully.');
}).catch((error) => console.log(error));
};
module.exports = {
api: functions.https.onRequest(getAllUsers),
};
I am getting the following error for invalid data:
FirebaseError: Function DocumentReference.update() called with invalid data. Unsupported field value: undefined (found in field email)
Any ideas?