Home > OS >  get clean data in firebase query
get clean data in firebase query

Time:12-14

I am making a query to retrieve information from my current user, the query works perfectly but the data I receive has a lot of information.

enter image description here

I would like to get only the object where the user information is.

This is my query:

export const GetUserDB = async (userId) => {
    const response = await db
        .collection('users')
        .where("id", "==", userId)
    return response.get();
}

CodePudding user response:

Let me know if it worked for you.

export const GetUserDB = async (userId) => {
    const response = await db
        .collection('users')
        .where("id", "==", userId)
        .get()
    const usersArray = response.docs.map(each => each.data())
    return usersArray[0] // returning the first document from the array
}

  • Related