I using firebase on project and write by nodejs. I have method write nodejs get all document in collection user by phone.
const phone = await admin.firestore().collection('users').where('phone_number', '==', phone).get()
Now i want filter if any document by phone not have field deleted_at i return it. Because firebase not support undefined by where i must write function filter it. This is my function
const doc = await getId(phone)
async function getId(phone) {
var result = null;
phone.docs.map(async doc => {
if (doc.exists && doc.data().deleted_at === undefined) {
result = doc
}
}
)
return result
}
When i using console log await getId(phone)
. It alway return me undefined. But when i change to doc.id it return me correct id i want. I have a question : How to return correct doc in collection. When it returns a doc , I can use it normally such as :
doc.ref.collection("Some sub collection on doc")
without re querying : await admin.firestore().collection('users').where('phone_number', '==', phone).get()
firebase by phone number ?