我有这个错误:
core.js:1440 ERROR Error: Uncaught (in promise): FirebaseError:
[code=invalid-argument]: Invalid document reference.
Document references must have an even number of segments, but users has 1
FirebaseError: Invalid document reference.
Document references must have an even number of segments, but users has 1
at new FirestoreError (error.js:149)
at Function.DocumentReference.forPath (database.js:436)
at Firestore.doc (database.js:245)
at AngularFirestore.doc (firestore.js:28)
at new Firebase (firebase.service.ts:25)
at _createClass (core.js:10877)
at _createProviderInstance$1 (core.js:10847)
at resolveNgModuleDep (core.js:10832)
at NgModuleRef_.get (core.js:12069)
at resolveDep (core.js:12559)
at new FirestoreError (error.js:149)
at Function.DocumentReference.forPath (database.js:436)
at Firestore.doc (database.js:245)
at AngularFirestore.doc (firestore.js:28)
at new Firebase (firebase.service.ts:25)
at _createClass (core.js:10877)
at _createProviderInstance$1 (core.js:10847)
at resolveNgModuleDep (core.js:10832)
at NgModuleRef_.get (core.js:12069)
at resolveDep (core.js:12559)
at resolvePromise (zone.js:821)
at resolvePromise (zone.js:785)
at eval (zone.js:870)
at ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:4724)
at ZoneDelegate.invokeTask (zone.js:420)
at Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:594)
at <anonymous>
async login() {
let u = await this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleAuthProvider())
console.log(u);
return this.getUserData(u.user.email);
}
public updateUser(UserName,phone)
{
this.userRef.doc(this.getEmail()).set({
UserName:UserName,
phone:phone,
});
this.router.navigate(["home"]);
}
login.component.ts中的login(){
this.firebaseService.updateUser(this.UserName,this.phone);
}
login.component.html中的
<input type="text" [(ngModel)]="UserName" onsubmit="myFunction()" name="UserName" pattern="[A-Za-z]{}" placeholder="UserName">
<div id="UserName" style="color:transparent; display:none">
The user name is required.
</div>
<input type="number" [(ngModel)]="phone" name="phone" placeholder="Phone number">
<div id="PelephoneNumber" style="color:transparent; display:none">
The phone is required.
</div>
<button (click)=login() type="Submit" class="Submit" id="login-button">Login</button>
</form>
</div>
任何帮助?
答案 0 :(得分:0)
我认为您需要在此处分享更多代码。我们不知道this.userRef被设置为...而没有假设您正确设置,我将把它写成:
this.fireStore.collection('users').doc(this.getUserEmail()).update({name:'John Doe'});
1。)注意我使用更新,而不是设置。 Set将使用您传递的任何新数据完全覆盖文档。我假设您要使用更新,因为您的函数名称称为“updateUser()”
2。)我还假设this.getUserEmail()返回字符串。 .doc()方法需要一个与您尝试更新的文档的ID匹配的字符串。
如果你提供了更多的服务代码,我可能会提供更多帮助......