이제 MongoDB 호환성을 갖춘 Cloud Firestore Enterprise 버전을 사용할 수 있습니다.
자세히 알아보기
빠른 시작: 데이터베이스 만들기 및 연결
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Cloud Firestore Enterprise 버전에만 해당합니다.
|
MongoDB 호환성을 갖춘 Cloud Firestore 데이터베이스를 만들고 mongosh
도구로 연결하는 방법을 알아봅니다.
시작하기 전에
-
Firebase 프로젝트를 아직 만들지 않았다면 Firebase Console에서 프로젝트 추가를 클릭한 후 화면에 표시된 안내를 따라 Firebase 프로젝트를 만들거나 기존 Google Cloud 프로젝트에 Firebase 서비스를 추가합니다.
mongosh
도구 설치
MongoDB 호환성을 갖춘 Cloud Firestore 데이터베이스를 만들고 연결 문자열 가져오기
Firebase 콘솔에서 새 Firestore Enterprise 버전 데이터베이스를 만듭니다.
MongoDB 호환성을 갖춘 Cloud Firestore에는 Firestore Enterprise 버전이 필요합니다.
-
Firebase Console에서 Firestore 데이터베이스 페이지로 이동합니다.
Firestore 데이터베이스로 이동
- 인증할 데이터베이스를 클릭합니다.
- 탐색기 패널에서 more_vert 더보기를 클릭합니다.
- MongoDB 도구를 사용하여 연결을 선택합니다.
- 연결 문자열을 복사합니다.
연결 문자열은 데이터베이스의 UID(시스템 생성)와 데이터베이스 위치에 따라 달라집니다.
UID.LOCATION.firestore.goog
SCRAM 인증용 사용자 만들기
Google Cloud 콘솔에서 새 데이터베이스 사용자를 만들고 사용자에게 Identity and Access Management 권한을 할당합니다.
-
Google Cloud 콘솔에서 데이터베이스 페이지로 이동합니다.
데이터베이스로 이동
- 데이터베이스 목록에서 데이터베이스를 선택합니다.
- 탐색 메뉴에서 인증을 클릭합니다.
- 사용자 추가를 클릭합니다.
- 사용자 이름을 입력합니다.
- 사용자의 Identity and Access Management 역할을 선택합니다.
- 만들기를 클릭합니다. 데이터베이스에서 사용자를 만들고 생성된 사용자의 비밀번호를 표시합니다. 이 비밀번호를 복사하여 저장하세요. 나중에 이 비밀번호를 가져올 수 없습니다.
mongosh
를 사용하여 연결
연결 문자열, 사용자 이름, 비밀번호를 사용하여 데이터베이스에 연결하고 다음 구성 옵션으로 로컬에서 mongosh
를 실행합니다.
mongosh 'mongodb://USERNAME:PASSWORD@CONNECTION_STRING:443/DATABASE_ID?loadBalanced=true&authMechanism=SCRAM-SHA-256&tls=true&retryWrites=false'
다음을 바꿉니다.
- USERNAME: 생성한 데이터베이스 사용자의 이름
- PASSWORD: 생성된 데이터베이스 사용자의 비밀번호
- CONNECTION_STRING: 데이터베이스 연결 문자열
- DATABASE_ID: 데이터베이스 ID
연결되면 다음 예와 같이 데이터를 만들고 읽을 수 있습니다.
db.pages.insertOne({ message: "Hello World!"})
db.pages.find({})
exit
다음 단계
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-28(UTC)
[null,null,["최종 업데이트: 2025-08-28(UTC)"],[],[],null,["\u003cbr /\u003e\n\n\n|--------------------------------------------------------|\n| *Relevant to Cloud Firestore Enterprise edition only.* |\n\n\u003cbr /\u003e\n\nLearn how to create a Cloud Firestore with MongoDB compatibility database and connect to it with the\n`mongosh` tool.\n\nBefore you begin\n\n1. If you haven't already, create a Firebase project: In the [Firebase console](//console.firebase.google.com/), click **Add project** , then follow the on-screen instructions to create a Firebase project or to add Firebase services to an existing Google Cloud project.\n2. [Install the `mongosh` tool](https://www.mongodb.com/docs/mongodb-shell/install/)\n\n\u003cbr /\u003e\n\nCreate a Cloud Firestore with MongoDB compatibility database and retrieve the connection string In the Firebase console, create a new Firestore Enterprise edition database. Cloud Firestore with MongoDB compatibility requires Firestore Enterprise edition:\n1. In the Firebase console, go to the **Firestore Database** page.\n\n [Go to Firestore Database](//console.firebase.google.com/project/_/firestore/databases/-default-/data/)\n2. Click the database that you want to authenticate.\n3. In the **Explorer** panel, click more_vert **View more**.\n4. Select **Connect using MongoDB tools**.\n5. Copy the connection string.\n\n\u003cbr /\u003e\n\nThe connection string depends on the UID of the database (system-generated)\nand the location of database: \n\n```text\nUID.LOCATION.firestore.goog\n```\n\nCreate a user for SCRAM authentication\n\nIn the Google Cloud console, create a new database user and assign\nthe user Identity and Access Management permissions.\n\n1. In the Google Cloud console, go to the **Databases** page.\n\n [Go to Databases](https://console.cloud.google.com/firestore/databases)\n2. Select the database from the list of databases.\n3. In the navigation menu, click **Auth**.\n4. Click **Add User**.\n5. Enter a username.\n6. Select an Identity and Access Management role for the user.\n7. Click create. The database creates a user and shows you the user's generated password. **Copy and save this password. You will not be able to retrieve\n this password later.**.\n\nConnect using `mongosh`\n\nUse the connection string, username, and password to connect to your\ndatabase, run `mongosh` locally with the following configuration options. \n\n```gdscript\nmongosh 'mongodb://\u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e:\u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e@\u003cvar translate=\"no\"\u003eCONNECTION_STRING\u003c/var\u003e:443/\u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e?loadBalanced=true&authMechanism=SCRAM-SHA-256&tls=true&retryWrites=false'\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eUSERNAME\u003c/var\u003e: the name of the database user you created.\n- \u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e: the generated password for the database user you created.\n- \u003cvar translate=\"no\"\u003eCONNECTION_STRING\u003c/var\u003e: the database connection string.\n- \u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e: a database ID\n\nOnce connected, you can create and read data, for example: \n\n```text\ndb.pages.insertOne({ message: \"Hello World!\"})\ndb.pages.find({})\nexit\n```\n\nWhat's next\n\n- [See a list of supported features](/docs/firestore/enterprise/supported-data-types-drivers)\n- [Learn about behavior differences in Cloud Firestore with MongoDB compatibility](/docs/firestore/enterprise/behavior-differences)\n- [Learn about additional authentication methods](/docs/firestore/enterprise/connect)"]]