javascript - FirebaseError:使用无效数据调用函数 Query.where()。不支持的字段值:未定义
问题描述
我只想获取 where 指定的文档。
在新注册时将在 uid 属性中注册的电子邮件地址作为值存储在 Firestore 中。
async signUp() {
const db = firebase.firestore();
await this.$store.dispatch('signUp', { username:this.username, email:this.email, password:this.password });
await db.collection('myData').doc(this.username).set({
uid: this.email,
email: this.email,
myWallet: 1000
});
this.$router.push('/home');
}
async signUp({ commit }, userInfomation) {
try {
await firebase
.auth()
.createUserWithEmailAndPassword(
userInfomation.email,
userInfomation.password
);
const user = firebase.auth().currentUser;
await user.updateProfile({
displayName: userInfomation.username,
});
commit('setUserName', user);
} catch (e) {
alert(e.message);
}
},
mutations: {
setUserName(state, user) {
state.userName = user.displayName;
},
actions: {
async getMyWallet({ commit, state }) {
const uid = state.updateUserName.email; //Information on the logged-in user is stored in updateUserName.
const db = firebase.firestore();
const doc = await db
.collection('myData')
.where('uid', '==', uid)
.get();
commit('getMyWallet', doc);
}
}
当我运行它时,我得到了标题中写的错误。
是不是写错了?
有没有其他好办法?
async getMyWallet({ commit }) {
firebase.auth().onAuthStateChanged(user => {
const uid = user.email;
const db = firebase.firestore();
const doc = db
.collection('myData')
.where('uid', '==', uid)
.get();
commit('getMyWallet', doc);
});
},
当我重写 getMyWallet 部分时,出现了一个新错误。
错误详情:doc.data 不是函数
解决方案
推荐阅读
- highcharts - 如何在 react-highcharts 中使用 Highcharts.setOptions?
- html - 为什么我的块的内容会在其他块上溢出?
- firebase - Flutter Dart with Firestore,如何从一个集合中获取参考文档?
- nativescript - 向远程人员显示 NativeScript 预览
- c - 为什么 itoa 期望有符号字符而不是无符号字符?
- azure - 在 CircleCI 中找不到 postgres_1 的容器
- css - 第一个,第二个和第三个元素单独使用仅 CSS
- sql - 选择几行到几个变量中 - Oracle PL/SQL
- html - 在网页问题上粘贴元素(子菜单)
- html - 自定义 CAF 接收器 html