【发布时间】:2017-10-17 17:15:47
【问题描述】:
被这个问题困扰了一段时间,所以我想做的是: 当我创建表单时,将表单连同用户列表以及他们的电子邮件地址一起写入数据库 - 如下所示:
formsById -> formId -> userId(包含用户电子邮件地址)
然后我可以像这样过滤当前用户的所有表单:
getFormList() {
return firebase.database().ref('/formsByID').orderByChild('userList').startAt(this.userId).endAt(this.userId);
}
这是我目前写入数据库的方式:
writeNewForm(formName: string, formDate: string): Promise<any> {
// A post entry.
let postData = {
name: formName,
date: formDate,
userList: this.userId // I want to nest the email in here
};
// Get a key for a new Post.
let newPostKey:string = this.formListRef.push().key;
// Write the new post's data simultaneously in the posts list and the user's post list.
let updates = {};
// write to the users record
updates[this.userPath + '/' + newPostKey] = true; // just set this to true be
updates[this.formsByIdPath + '/' + newPostKey] = postData;
return this.rootRef.update(updates);
//return rootRef.update(updates);
}
但我不知道如何将我的用户电子邮件地址嵌套在他们的 ID 下。
任何帮助表示赞赏。
【问题讨论】:
标签: angular ionic-framework firebase-realtime-database