How to get two queries from firestore?

147
January 10, 2020, at 11:20 AM

I use redux and want to know how to take and process two queries from firesotre.

export function getBlackList(data) {
    return (dispatch, getState) => {
        let db = loadFB().firestore();
        let query = db.collection('users').where("report.total_point",">",0).orderBy("report.total_point","asc");
        return query.get().then(docs=>{
            let result = [];
            console.log(result);
            docs.forEach(doc=>{
                let user = doc.data();
                user.id = doc.id;
                result.push(user);
            })
            dispatch({
                type: types.SET_USER_LIST,
                data: result,
                page : 1
            })

        })
    }
}

Through the code presented above, the component is processed through dispatch.

I get a query But I want to know how to get the two query values ‚Äč‚Äčtogether and sort them.

db.collection('users').where("memo",">","0").orderBy("memo","asc");

Is there a way to solve it using "promise all"?

Look forward to a good solution.

Answer 1

Your query will return multiple items. Get them together you can use map and sort if you need.

Then the call to dispatch for redux looks ok to me.

query.get().then(docs => {
  const users = docs.map(doc => ({
    id: doc.id,
    ...doc.data(),
  }));
  // .sort(...)
  dispatch({
    type: types.SET_USER_LIST,
    data: users,
    page: 1,
  });
});
READ ALSO
Initialize using patchValue for template driven forms

Initialize using patchValue for template driven forms

I use template driven and am trying to initialize my form using patchValue and it is not working

144
Re-posting <input> value into <textarea>

Re-posting <input> value into <textarea>

I want to re-generate user's input values onto textarea with specific formatI've created input and 'select' with various 'options' inside as well as 'button' that triggers the function

86
currently no loaders are configured to process this file form vuepress

currently no loaders are configured to process this file form vuepress

I want to import third-party libraries went I use the vuepressI should config a rule to compile node_modules js file

328