Cloud Firestore: how to reference another document?

Christian

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?

npesa92

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]

編集
0

コメントを追加

0

関連記事

分類Dev

Not able to reference Firestore document path

分類Dev

How to listen for document changes in Cloud Firestore using Flutter?

分類Dev

Firebase cloud functions: How to get the reference to the document with wildcard notation?

分類Dev

Deleting document from cloud_firestore in flutter

分類Dev

Firebase Cloud Firestore - Accessing a collection from a reference

分類Dev

how to set validation rules to permit document creation only if documents with the same fields are not present with Cloud Firestore

分類Dev

How to clone a node to another path based on a reference value from the initial path on Google Cloud Functions?

分類Dev

Cloud function for firestore onWrite event very rarely not triggered by a document update

分類Dev

Does one document or one field is charged as one read in cloud firestore?

分類Dev

Firestore update with merge - how to overwrite a part of the document

分類Dev

How to prevent unnecessary Document read in Firestore?

分類Dev

How to update the propriety of a field objects in a firestore document?

分類Dev

How can i import JSON into Cloud Firestore

分類Dev

How to access Cloud Firestore from Google Sheets?

分類Dev

How to access Cloud Firestore from Google Sheets?

分類Dev

How can I reference a enum in another enum

分類Dev

Cloud Functions&Firestore:document.dataを反復処理します

分類Dev

How do I get data in subcollection from filtered document in Firestore

分類Dev

How to get all of the collection ids from document on Firestore?

分類Dev

How to delete a document when multiple conditions are matched, firestore firebase

分類Dev

how to delete specific firestore document in Source.CACHE?

分類Dev

How to query using unique document id in Firestore from flutter?

分類Dev

How to create a collection inside a uid document in Firestore using Flutter?

分類Dev

how to set custom object with document id to a collection in firestore in flutter?

分類Dev

How to add map inside document in firestore using flutter?

分類Dev

How can a Cerberus dependency reference a field higher up in the document?

分類Dev

How can I upload files to Cloud Storage through Cloud Functions and use Firestore to control access to Cloud Storage?

分類Dev

mongodb for each document retrieve its fields + count of its id in another collection by reference

分類Dev

How to enable Cloud Firestore Native Mode using API / command line?

Related 関連記事

  1. 1

    Not able to reference Firestore document path

  2. 2

    How to listen for document changes in Cloud Firestore using Flutter?

  3. 3

    Firebase cloud functions: How to get the reference to the document with wildcard notation?

  4. 4

    Deleting document from cloud_firestore in flutter

  5. 5

    Firebase Cloud Firestore - Accessing a collection from a reference

  6. 6

    how to set validation rules to permit document creation only if documents with the same fields are not present with Cloud Firestore

  7. 7

    How to clone a node to another path based on a reference value from the initial path on Google Cloud Functions?

  8. 8

    Cloud function for firestore onWrite event very rarely not triggered by a document update

  9. 9

    Does one document or one field is charged as one read in cloud firestore?

  10. 10

    Firestore update with merge - how to overwrite a part of the document

  11. 11

    How to prevent unnecessary Document read in Firestore?

  12. 12

    How to update the propriety of a field objects in a firestore document?

  13. 13

    How can i import JSON into Cloud Firestore

  14. 14

    How to access Cloud Firestore from Google Sheets?

  15. 15

    How to access Cloud Firestore from Google Sheets?

  16. 16

    How can I reference a enum in another enum

  17. 17

    Cloud Functions&Firestore:document.dataを反復処理します

  18. 18

    How do I get data in subcollection from filtered document in Firestore

  19. 19

    How to get all of the collection ids from document on Firestore?

  20. 20

    How to delete a document when multiple conditions are matched, firestore firebase

  21. 21

    how to delete specific firestore document in Source.CACHE?

  22. 22

    How to query using unique document id in Firestore from flutter?

  23. 23

    How to create a collection inside a uid document in Firestore using Flutter?

  24. 24

    how to set custom object with document id to a collection in firestore in flutter?

  25. 25

    How to add map inside document in firestore using flutter?

  26. 26

    How can a Cerberus dependency reference a field higher up in the document?

  27. 27

    How can I upload files to Cloud Storage through Cloud Functions and use Firestore to control access to Cloud Storage?

  28. 28

    mongodb for each document retrieve its fields + count of its id in another collection by reference

  29. 29

    How to enable Cloud Firestore Native Mode using API / command line?

ホットタグ

アーカイブ