빠른 시작: 데이터베이스 만들기 및 연결
MongoDB 호환성을 갖춘 Firestore 데이터베이스를 만들고 mongosh
도구로 연결하는 방법을 알아봅니다.
시작하기 전에
-
In the Google Cloud console, go to the project selector page.
-
Select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Make sure that you have the following role or roles on the project: Cloud Datastore Owner
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
IAM으로 이동 - 프로젝트를 선택합니다.
- 액세스 권한 부여를 클릭합니다.
-
새 주 구성원 필드에 사용자 식별자를 입력합니다. 일반적으로 Google 계정의 이메일 주소입니다.
- 역할 선택 목록에서 역할을 선택합니다.
- 역할을 추가로 부여하려면 다른 역할 추가를 클릭하고 각 역할을 추가합니다.
- 저장을 클릭합니다.
mongosh
도구 설치MongoDB 호환성을 갖춘 Firestore 데이터베이스를 만들고 연결 문자열 가져오기
Google Cloud 콘솔에서 새 Firestore Enterprise 버전 데이터베이스를 만듭니다. MongoDB 호환성을 갖춘 Firestore에는 Firestore Enterprise 버전이 필요합니다.-
Google Cloud 콘솔에서 데이터베이스 페이지로 이동합니다.
- Firestore 데이터베이스 만들기를 클릭합니다.
- 데이터베이스 ID를 입력합니다.
- Enterprise 버전을 선택합니다.
- 데이터베이스의 위치를 선택합니다.
데이터베이스 만들기를 클릭합니다.
데이터베이스 초기화가 완료되면 콘솔에서 데이터베이스의 Firestore 스튜디오가 열립니다.
-
외부 MongoDB 도구를 사용하여 Firestore에 연결 섹션에서 연결 문자열을 복사합니다.
연결 문자열은 데이터베이스의 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
다음 단계
-