이제 MongoDB 호환성을 갖춘 Firestore Enterprise 버전을 사용할 수 있습니다.
자세히 알아보기
데이터 구조 선택
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
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 software
name : "software chat"
- collections_bookmark
users
- class
alovelace
first : "Ada"
last : "Lovelace"
- class
sride
first : "Sally"
last : "Ride"`
- class astrophysics
|
루트 수준 컬렉션
데이터베이스 루트 수준에 컬렉션을 만들어 상이한 데이터 세트를 정리합니다.
- 장점: 루트 수준 컬렉션은 다대다 관계에 적합하며 각 컬렉션 내에서 강력한 쿼리를 제공합니다.
-
제한사항: 데이터베이스가 커지면 내재적으로 계층 구조를 가진 데이터 가져오기가 더욱 복잡해질 수 있습니다.
- 가능한 사용 사례: 동일한 채팅 앱에서 사용자 컬렉션 하나와 채팅방 및 메시지 컬렉션 하나를 만들 수 있습니다.
|
- 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 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 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 : \"...\" |"]]