I'm using Angularfire2. Suppose I have a users
and comments
collections. When adding a comment, what would be the correct way of referencing the user who created the comment? At first I thought I could simply create a comment with a structure like this:
{
message: string,
user: {
uid: string,
username: string,
...
}
}
But then the problem is if the user updates his profile, then the data here would be incorrect. Is it possible to simply supply the user's id when creating the comment and get the entire user's data when querying the comments?
Using firestore, you can save that field as a DocumentReference which is a ref to a document in another collection. This makes it so that field acts as it's own observable inside the 'Comment' observable. This article demonstrates how to set the reference path when setting or updating a document: https://groups.google.com/forum/m/#!topic/firebase-talk/UTgW7WwKFTU
Firestore offers a variety of data types explained here that are supported natively: https://firebase.google.com/docs/firestore/manage-data/data-types
I hope this can be of help!
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加