TURAN BİCAV
TURAN BİCAV

Reputation: 71

I can't filter firestore for React native

I can't get any output in console, I want to sync 'title' to 'asdasd' which I want to do.

 async function getPost (){
          
        const li = [];
      const storeDb=firebase.firestore()

      const postDetailsRef = collection(storeDb,'Post');

      const postQuery = query(postDetailsRef,where('title', '==','asdasdt'));

      const querySnapshot = await getDocs(postQuery);

      querySnapshot.forEach((doc)=>{
        console.log('hop doc',doc.data())
      })
}

enter image description here

Upvotes: 0

Views: 157

Answers (1)

muhammad ripqi
muhammad ripqi

Reputation: 111

I tried this with my firestore and it's working properly

const db = getFirestore(firebaseApp);
const test = query(collection(db, 'development', data.id, 'messages'), where('index','==', 1));
    const testSnapshot = await getDocs(test);
    testSnapshot.docs.map(doc => 
    {
      console.log( doc.data())
    });

because you are using getDocs and query, i assume you use modular firebase v9. Try changing

const storeDb=firebase.firestore() 

to

const storeDb = getFirestore(yourfirebaseApp);

according to this firebase document

Upvotes: 1

Related Questions