现已推出具有 MongoDB 兼容性的 Firestore 企业版!
了解详情。
בחירת מבנה נתונים
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
חשוב לזכור שכאשר יוצרים מבנה לנתונים ב-Cloud Firestore, יש כמה אפשרויות שונות:
- לכתוב מסמכים
- אוספים מרובים
- קולקציות משנה בתוך מסמכים
כדאי לשקול את היתרונות של כל אפשרות בהקשר של תרחיש השימוש שלכם. במדריך הזה מפורטים כמה מבנים לדוגמה של נתונים היררכיים.
נתונים מקוננים במסמכים
אפשר להוסיף אובייקטים מורכבים כמו מערכים או מפות בתוך מסמכים.
- יתרונות: אם יש לכם רשימות פשוטות וקבועות של נתונים שאתם רוצים לשמור במסמכים, קל להגדיר את זה וזה מייעל את מבנה הנתונים.
-
מגבלות:
האפשרות הזו לא ניתנת להרחבה כמו אפשרויות אחרות,
במיוחד אם הנתונים גדלים עם הזמן. ככל שהרשימות גדולות יותר או גדלות, המסמך גדל גם הוא, מה שעלול להוביל לזמני אחזור ארוכים יותר של המסמך.
- מהו תרחיש שימוש אפשרי? לדוגמה, באפליקציית צ'אט, אפשר לאחסן בפרופיל של המשתמש רשימה מקוננת של 3 חדרי הצ'אט שהוא ביקר בהם לאחרונה.
|
- class alovelace
- name :
first : "Ada"
last : "Lovelace"
born : 1815
rooms :
0 : "Software Chat"
1 : "Famous Figures"
2 : "Famous SWEs"
|
אוספי משנה
אתם יכולים ליצור אוספים בתוך מסמכים אם יש לכם נתונים שעשויים להתרחב עם הזמן.
- יתרונות: ככל שהרשימות גדלות, הגודל של מסמך האב לא משתנה. יש לכם גם יכולות מלאות של שאילתות על אוספי משנה, ואתם יכולים להנפיק
שאילתות של קבוצות אוספים על אוספי משנה.
-
מגבלות: אי אפשר למחוק בקלות אוספי משנה.
- מהו תרחיש שימוש אפשרי? באפליקציית צ'אט, למשל, אפשר ליצור אוספים של משתמשים או הודעות במסמכים של חדר הצ'אט.
|
- collections_bookmark science
- class תוכנה
name : "software chat"
- collections_bookmark
users
- class
alovelace
first : "Ada"
last : "Lovelace"
- class
sride
first : "Sally"
last : "Ride"`
- class אסטרופיזיקה
|
אוספים ברמת הבסיס
יוצרים אוספים ברמת הבסיס של מסד הנתונים כדי לארגן מערכי נתונים שונים.
- יתרונות: קולקציות ברמת הבסיס מתאימות ליחסי רבים לרבים ומאפשרות לבצע שאילתות עוצמתיות בכל קולקציה.
-
מגבלות: ככל שהמסד גדל, יכול להיות שיהיה יותר ויותר מסובך לקבל נתונים שהם היררכיים באופן טבעי.
- מהו תרחיש שימוש אפשרי? באותה אפליקציית צ'אט, לדוגמה, אפשר ליצור אוסף אחד למשתמשים ואוסף אחר לחדרים ולהודעות.
|
- collections_bookmark
users
- class alovelace
first : "Ada"
last : "Lovelace"
born : 1815
- class sride
first : "Sally"
last : "Ride"
born : 1951
- collections_bookmark rooms
- class software
- collections_bookmark
messages
- class
message1
from : "alovelace"
content : "..."
- class
message2
from : "sride"
content : "..."
|
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-16 (שעון UTC).
[null,null,["עדכון אחרון: 2025-08-16 (שעון UTC)."],[],[],null,["\u003cbr /\u003e\n\nRemember, when you structure your data in Cloud Firestore, you\nhave a few different options:\n\n- Documents\n- Multiple collections\n- Subcollections within documents\n\nConsider the advantages of each option as they\nrelate to your use case. A few example structures for hierarchical data\nare outlined in this guide.\n\n\u003cbr /\u003e\n\nNested data in documents\n\nYou can nest complex objects like arrays or maps within documents.\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|\n| - **Advantages:** If you have simple, fixed lists of data that you want to keep within your documents, this is easy to set up and streamlines your data structure. - **Limitations:** This isn't as scalable as other options, especially if your data expands over time. With larger or growing lists, the document also grows, which can lead to slower document retrieval times. - **What's a possible use case?** In a chat app, for example, you might store a user's 3 most recently visited chat rooms as a nested list in their profile. | - class alovelace - name : first : \"Ada\" last : \"Lovelace\" born : 1815 rooms : 0 : \"Software Chat\" 1 : \"Famous Figures\" 2 : \"Famous SWEs\" |\n\nSubcollections\n\nYou can create collections within documents when you have data that might expand\nover time.\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - **Advantages:** As your lists grow, the size of the parent document doesn't change. You also get full query capabilities on subcollections, and you can issue [collection group queries](../query-data/queries) across subcollections. - **Limitations:** You can't easily delete subcollections. - **What's a possible use case?** In the same chat app, for example, you might create collections of users or messages within chat room documents. | - collections_bookmark science - class software name : \"software chat\" - collections_bookmark users - class alovelace first : \"Ada\" last : \"Lovelace\" - class sride first : \"Sally\" last : \"Ride\"\\` \u003cbr /\u003e \u003cbr /\u003e - class astrophysics - ... |\n\nRoot-level collections\n\nCreate collections at the root level of your database to organize disparate data\nsets.\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - **Advantages:** Root-level collections are good for many-to-many relationships and provide powerful querying within each collection. - **Limitations:** Getting data that is naturally hierarchical might become increasingly complex as your database grows. - **What's a possible use case?** In the same chat app, for example, you might create one collection for users and another for rooms and messages. | - collections_bookmark users - class alovelace first : \"Ada\" last : \"Lovelace\" born : 1815 - class sride first : \"Sally\" last : \"Ride\" born : 1951 - collections_bookmark rooms - class software - collections_bookmark messages - class message1 from : \"alovelace\" content : \"...\" - class message2 from : \"sride\" content : \"...\" |"]]