在 Where 子句中使用变量的云 Firestore 查询不起作用。扑动



我已经声明了一个全局变量,并在应用程序的initState()函数中定义了它。

但是,稍后在云firestore查询的Whater子句中使用该变量时,查询不起作用:

.where("email", isEqualTo: _userEmail.toString())

相反,查询与引号一起使用:

.where("email", isEqualTo: "myemail@xyz.com")

Firestore.instance.collection('Matrimonial').where("email", isEqualTo: _userEmail.toString()).getDocuments();

不工作

Firestore.instance.collection('Matrimonial').where("email", isEqualTo: "myemail@xyz.com").getDocuments();

工作

我找到了一种使用Vuefire在WHERE子句中使用可变参数的方法:

watch: {
    userProfile () {
      this.$bind('allUsers', this.$db.collection('users').where('institution', '==', this.userProfile.institution))
    }
  }

这种情况,因为不同的管理员登录并成为当前使用者,然后他们只能查看其机构的所有用户。

迟到回应,但是我正在搜索或对此问题的答案,并且使用字符串插值对我有用:

Firestore.instance.collection('Matrimonial').where("email", isEqualTo: `${_userEmail.toString()}`).getDocuments();