Home > Blockchain >  I tried to get data using filter in nodejs and firestore when show me this error "Cannot read p
I tried to get data using filter in nodejs and firestore when show me this error "Cannot read p

Time:09-27

I tried to get data using filter in nodejs and firestore when show me this error in postman

"Cannot read properties of undefined (reading '_internalPath')"

my code

const getAllWords = async (req, res, next) => {
     let categoryName = "fruits"
    
    try {
        const word = await firestore.collection('12words');
        const data = await word.where({categoryName}).get();
        const wordArray = []; 
        if(data.empty) {
            res.status(404).send('No words12  found');
        }else {
            data.forEach(doc => {
                const words = new Word12(
                    doc.id,
                    doc.data().name,
                    doc.data().categoryName,
                    
                );
                wordArray.push(words);
            });
            res.send(wordArray);
        }
    } catch (error) {
        res.status(400).send(error.message);
    }
}

CodePudding user response:

The .where() takes 3 parameters (fieldPath, opStr, value) but you are passing only 1 object. Try refactoring the code as shown below:

// replace fieldName with the field name in document
const data = await word.where("fieldName", "==", categoryName).get();
  • Related