我如何在 .where() - Firestore React Native 中使用变量?

How can i use veriable in .where() - Firestore React Native ?

我想通过在 Where Query 中使用 veriable 从 User Collection 获取用户数据。我使用此代码但未检索到数据:

export const userAddToOrganization = (email) => {  
    return (dispatch) => {
      if (email !== '') {
        console.log('email' , email); //'e@e.com √'
      firebase.firestore().collection('users').where("email", '==', `${email}`)
      .get()
      .then((querySnapshot) => {
        querySnapshot.forEach((doc) => {
          console.log(doc.id, "=>", doc.data());
        });
      });
    }
    };
   };

当我使用 'e@e.com' 时,数据检索成功。但我想使用 veriable (email)

 export const userAddToOrganization = (email) => {  
    return (dispatch) => {
      if (email !== '') {
        console.log('email' , email);
      firebase.firestore().collection('users').where("email", '==', 'e@e.com')
      .get()
      .then((querySnapshot) => {
        querySnapshot.forEach((doc) => {
          console.log(doc.id, "=>", doc.data());
        });
      });
    }
    };
   };

如何在 WHERE 查询中使用 veriable 获取数据。 谢谢。

export const userAddToOrganization = (email) => {  
return (dispatch) => {
  if (email !== '') {
    console.log('email' , email); //'e@e.com √'
  const ref = firebase.firestore().collection('users')
   ref.where("email", '==', email)
  .get()
  .then((querySnapshot) => {
    querySnapshot.forEach((doc) => {
      console.log(doc.id, "=>", doc.data());
    });
  });
  }
 };
};

我还没有测试过它,但我看不出它为什么不起作用。删除字符串文字并直接传递电子邮件。如果那不起作用,那么我想是 trim 字符串,它会删除所有额外的 space.

export const userAddToOrganization = (email) => {  
return (dispatch) => {
  if (email !== '') {
    console.log('email' , email); //'e@e.com √'
  const ref = firebase.firestore().collection('users')

  ref.where("email", '==', email.trim())
  .get()
  .then((querySnapshot) => {
    querySnapshot.forEach((doc) => {
      console.log(doc.id, "=>", doc.data());
    });
  });
  }
 };
};