클러스터에 대한 Connect 대화 상자는 MongoDB 클라이언트 라이브러리를 사용하여 애플리케이션으로 클러스터에 연결하기 위한 세부 정보를 제공합니다.
Select your language 드롭다운 메뉴를 사용하여 이 페이지에서 예시의 언어를 설정합니다.
전제 조건
드라이버 버전
사용 중인 드라이버 버전이 사용 중인 MongoDB 서버 버전과 호환되어야 합니다. 최신 데이터베이스 기능을 사용하고 향후 버전 업그레이드에 대비하려면 사용 중인 MongoDB 서버 버전과 호환되는 최신 드라이버를 선택하는 것이 좋습니다.
사용 중인 MongoDB 서버 버전에 대한 전체 기능이 포함된 드라이버 버전 목록은 해당 드라이버의 클라이언트 라이브러리 호환성 표 를 확인하세요.
중요
공식 지원 드라이버
Use officially supported MongoDB drivers at current versions for the best reliability and support experience. The Atlas SLA covers officially supported drivers only.
Atlas는 Community 드라이버 및 지원 종료 드라이버 버전에 대해 최선의 노력을 다하여 진단만 지원합니다. Atlas는 Community 드라이버를 테스트하거나 패치하거나 인증하지 않습니다. 지원을 통해 연결 문제가 플랫폼에서 발생하는지 드라이버에서 발생하는지 확인할 수 있지만 드라이버 코드는 디버그하지 않습니다.
학습하려면 Atlas의 Community 및 지원되지 않는 드라이버에 대한 지원 정책은 무엇입니까?를 참조하세요.
비공개 엔드포인트를 통한 샤딩된 클러스터에 대해 최적화된 연결 문자열
운전자 와 최적화된 연결 문자열사용하여 샤딩된 클러스터 에 연결할 수 있습니다.
TLS
Atlas 클러스터에 연결하려면 클라이언트가 TLS를 지원해야 합니다.
Clients must support the SNI TLS extension to connect to an Atlas Free cluster (formerly known as M0) or Flex cluster.
IP 액세스 목록
클러스터에 액세스하려면 Atlas 프로젝트의 IP 액세스 목록에 있는 IP 주소에서 연결해야 합니다. IP 액세스 목록에 IP 주소를 추가해야 하는 경우 Connect 대화 상자에서 추가할 수 있습니다. 네트워크 액세스 탭에서 IP 주소를 추가할 수도 있습니다.
데이터베이스 사용자
To access a cluster, you must have a database user with access to the desired databases on your Atlas cluster. Database users are separate from Atlas users. Database users have access to MongoDB databases, while Atlas users have access to the Atlas application itself.
Connect 대화 상자에서 Atlas 클러스터에 액세스할 데이터베이스 사용자를 생성할 수 있습니다. 클러스터 보기에서 데이터베이스 사용자를 추가할 수도 있습니다. Atlas는 첫 번째 클러스터를 생성할 때 데이터베이스 사용자를 생성합니다.
애플리케이션 연결
Atlas 에서 프로젝트 의 Clusters 페이지로 이동합니다.
아직 표시되지 않은 경우 탐색 표시줄의 Organizations 메뉴에서 원하는 프로젝트가 포함된 조직을 선택합니다.
아직 표시되지 않은 경우 탐색 표시줄의 Projects 메뉴에서 원하는 프로젝트를 선택합니다.
사이드바에서 Database 제목 아래의 Clusters를 클릭합니다.
Clusters(클러스터) 페이지가 표시됩니다.
Connection Security를 선택합니다.
Choose Connection Type 사용 가능한 버튼 세트에서.
참고
기능이 허용된 경우 옵션이 표시됩니다.
Private IP for Peering, Private Endpoint 혹은 모두를 활성화하면 Atlas에 연결 유형 옵션이 표시됩니다. 두 기능 중 하나를 허용하지 않은 경우 버튼이 표시되지 않고 Connection Type 기본값은 Standard로 설정됩니다.
허용된 공개 IP 주소에 대해 이 연결 유형을 사용하십시오.
피어링을 사용하도록 설정한 경우 이 연결 유형을 사용합니다.
Google Cloud 또는 Azure의 경우 피어링된 네트워크에서 드라이버에 연결 중이거나
AWS의 경우 사용자 지정 DNS 서비스를 사용하는 피어링 네트워크에서 드라이버와 연결합니다.
이들 중 어느 것도 적용되지 않으면 IP 주소를 IP 액세스 목록에 추가하고 표준 연결 문자열을 사용하세요. 사무실이나 홈 네트워크에서 Atlas에 직접 연결하는 경우 이 옵션을 선호할 수 있습니다.
참고
피어를 사용할 수 있어야 합니다.
피어 중 한 명이 AVAILABLE(으)로 표시되어 있지 않으면 이 옵션을 선택할 수 없습니다. 피어의 상태를 확인하는 방법을 학습하려면 Atlas 네트워크 피어링 연결 보기를 참조하세요.
참고
멀티 클라우드 클러스터
애플리케이션이 클러스터의 프라이머리와 동일한 클라우드 서비스 제공자에서 호스팅되지 않는 경우 애플리케이션은 세컨더리 읽기만 수행할 수 있습니다.
With multi-cloud clusters, consider adding the readPreference connection option to your connection string. Use one of the following values:
드라이버가 다음과 같은 이유로 비공개 엔드포인트 연결을 통해 드라이버와 연결하는 경우 적절한 인터페이스 엔드포인트에 연결 string 을 사용하세요.
클라우드 공급자 네트워크 내에서 실행되거나
클라우드 공급자 네트워크에 전이적 네트워크 액세스가 가능합니다.
최적화된 연결 문자열을 사용하려고 합니다.
이들 중 어느 것도 적용되지 않으면 IP 주소를 IP 액세스 목록에 추가하고 표준 연결 문자열을 사용하세요. 사무실이나 홈 네트워크에서 Atlas에 직접 연결하는 경우 이 옵션을 선호할 수 있습니다.
참고
구성된 PrivateLink 연결을 사용할 준비가 되지 않으면 이 옵션을 선택할 수 없습니다. AWS PrivateLink 상태를 확인하는 방법을 학습 비공개 엔드포인트 연결 문제 해결을 참조하세요.
클러스터에 대한 연결을 제한하는 방법을 선택합니다.
Add a Connection IP Address
중요
Setup connection security 단계에서 클러스터에 이미 IP 액세스 목록 항목을 구성했다고 Atlas가 표시하는 경우 이 단계를 건너뜁니다. IP 액세스 목록을 관리하려면 액세스 목록에 항목 추가를 참조하십시오.
Atlas는 프로젝트의 IP 액세스 목록 항목에서 클러스터에 대한 표준 클라이언트 연결을 허용합니다. 프로젝트 IP 액세스 목록은 특정 IP 또는 CIDR 주소로 API 액세스를 제한하는 API 액세스 목록과 다릅니다.
IP 액세스 목록이 비어 있으면 Atlas는 프로젝트의 IP 액세스 목록에 IP 주소를 추가하라는 메시지를 표시합니다. 둘 중 하나를 수행하면 됩니다.
현재 IP 주소에서 액세스를 허용하려면 Add Your Current IP Address을 클릭합니다.
Add an IP Address을 클릭하여 단일 IP 주소 또는 CIDR로 표기된 주소 범위를 추가합니다.
새로 추가된 IP 주소 또는 CIDR 범위에 대한 선택적 설명을 제공합니다. Add IP Address을 클릭하여 IP 액세스 목록에 주소를 추가합니다.
Add a Connection IP Address
중요
Setup connection security 단계에서 클러스터에 이미 IP 액세스 목록 항목을 구성했다고 Atlas가 표시하는 경우 이 단계를 건너뜁니다. IP 액세스 목록을 관리하려면 IP 액세스 목록에 항목 추가를 참조하세요.
Atlas는 프로젝트의 IP 액세스 목록 항목에서 클러스터에 대한 표준 클라이언트 연결을 허용합니다. 프로젝트 IP 액세스 목록은 특정 IP 또는 CIDR 주소로 API 액세스를 제한하는 API 액세스 목록과 다릅니다.
IP 액세스 목록이 비어 있으면 Atlas는 프로젝트의 IP 액세스 목록에 IP 주소를 추가하라는 메시지를 표시합니다. Add a Different IP Address을 클릭하여 단일 IP 주소 또는 CIDR로 표기된 주소 범위를 추가합니다.
새로 추가된 IP 주소 또는 CIDR 범위에 대한 선택적 설명을 제공합니다. Add IP Address을 클릭하여 IP 액세스 목록에 주소를 추가합니다.
Choose Connection Type에서 Private Endpoint을 선택합니다.
Private Link Type 옵션이 표시되면 다음 옵션 중 하나를 선택합니다.
Optimized SRV Connection 로드 밸런싱된 연결의 경우.
Legacy SRV Connection 로드 밸런싱되지 않은 연결의 경우.
자세한 학습은 비공개 엔드포인트 사용하여 샤딩된 클러스터의 연결 성능을 최적화하려면 어떻게 해야 하나요?를 참조하세요.
Choose Private Endpoint 아래에서 사용할 엔드포인트를 선택합니다.
데이터베이스 사용자를 생성합니다.
중요
Setup connection security 단계에서 프로젝트에 데이터베이스 사용자가 하나 이상 구성되어 있다고 Atlas에서 표시하는 경우 이 단계를 건너뛰세요. 기존 데이터베이스 사용자를 관리하려면 데이터베이스 사용자 구성을 참조하세요.
To access the cluster, you need a MongoDB user with access to the desired database or databases on the cluster in your project. If your project has no MongoDB users, Atlas prompts you to create a new user with the Atlas Admin role.
새로운 사용자의 Username을(를) 입력합니다.
이 새 사용자에 대한 Password를 입력하거나 Autogenerate Secure Password를 클릭합니다.
사용자를 저장하려면 Create Database User 을(를) 클릭합니다.
다음 단계에서 이 사용자를 통해 클러스터에 연결합니다.
IP 액세스 목록에 IP 주소를 추가하고 데이터베이스 사용자를 추가한 경우 Choose Your Connection Method 을(를) 클릭합니다.
드라이버 및 버전을 선택합니다.
드롭다운 메뉴에서 드라이버와 버전을 선택합니다. 연결 문자열이 포함된 코드 샘플이 표시됩니다. <password>를 데이터베이스 사용자를 만들 때 지정한 비밀번호로 바꿉니다.
Use this connection string in your application 아래에서, 연결 문자열은 기본적으로 SRV 형식(mongodb+srv://)을 사용합니다. 표준(SRV 아닌) 연결 문자열(mongodb://)을 보려면 SRV Connection String 토글을 중지합니다.
참고
비밀번호, 데이터베이스 이름 또는 연결 문자열에 예약된 URI 문자가 포함된 경우 해당 문자를 이스케이프 처리해야 합니다. 예를 들어 비밀번호가 @bc123인 경우 연결 문자열에 암호를 지정할 때 @ 문자를 이스케이프 처리해야 합니다 (예시: %40bc123). 자세한 내용은 연결 문자열 비밀번호의 특수 문자를 참조하세요.
자세한 내용은 드라이버 호환성을 참조하세요.
드라이버 예시
In the following example, you authenticate and connect to an Atlas cluster by using a URI connection string. Replace the placeholders in the example with your credentials and deployment details.
참고
Atlas M0 무료 클러스터 또는 Flex 클러스터에 연결하려면 MongoDB 7.0 이상을 지원하는 C 드라이버 버전을 사용해야 합니다. C 드라이버와 MongoDB 간의 호환성에 대한 전체 문서는 MongoDB 호환성 매트릭스를 참조하세요. 드라이버를 최신 버전으로 업그레이드하는 것을 권장합니다.
client = mongoc_client_new ("mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority"); db = mongoc_client_get_database (client, "<databaseName>");
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
MongoDB 7.0 이상 | 버전 1.11 이상 |
행동
참고
다음 구성 옵션은 C 운전자 단일 스레드 모드 로 실행 경우에만 적용 .
MongoDB 드라이버는 클러스터 투표 또는 페일오버 이벤트 후 자동으로 서버 선택을 시도합니다. 기본적으로 C 드라이버는 첫 번째 서버 선택 시도가 실패하면 즉시 오류를 발생시킵니다. 다음 구성 설정은 서버 선택 루프에서 더 많은 시간을 소비하는 대신 Atlas 클러스터에 대한 애플리케이션 연결을 개선할 수 있습니다.
Set serverSelectionTryOnce to
falseto direct the C driver to perform server selection up to the time limit defined byserverSelectionTimeoutMS.Lower the serverSelectionTimeoutMS to
15000from the default of30000. MongoDB elections typically take 10 seconds, but can be as fast as 5 seconds on Atlas. Setting this value to 15 seconds (15000milliseconds) covers the upper bound of election plus additional time for latency.
참고
To connect to an Atlas M0 Free cluster or a Flex cluster, you must use a C++ driver version that supports MongoDB 7.0 and later. For complete documentation on compatibility between the C++ driver and MongoDB, see the MongoDB compatibility matrix. We recommend that you upgrade to the latest version of the driver.
//... mongocxx::instance inst{}; mongocxx::client conn{mongocxx::uri{"mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority"}}; mongocxx::database db = conn["<databaseName>"];
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
참고
레거시 C++ 드라이버는 수명이 종료되어 더 이상 지원되지 않습니다.
행동
참고
다음 구성 옵션은 C++ 드라이버의 단일 스레드 mongocxx::client 클래스를 사용하여 Atlas 클러스터에 연결하는 경우에만 적용됩니다.
MongoDB 드라이버는 클러스터 투표 또는 페일오버 이벤트 후 자동으로 서버 선택을 시도합니다. 기본적으로 C++ 드라이버는 첫 번째 서버 선택 시도가 실패하면 즉시 오류를 발생시킵니다. 다음 구성 설정은 서버 선택 루프에서 더 많은 시간을 소비하는 대신 Atlas 클러스터에 대한 애플리케이션 연결을 개선할 수 있습니다.
Set serverSelectionTryOnce to
falseto direct the C++ driver to perform server selection up to the time limit defined byserverSelectionTimeoutMS.Lower the serverSelectionTimeoutMS to
15000from the default of30000. MongoDB elections typically take 10 seconds, but can be as fast as 5 seconds on Atlas. Setting this value to 15 seconds (15000milliseconds) covers the upper bound of election plus additional time for latency.
참고
To connect to an Atlas M0 Free cluster or a Flex cluster, you must use a C#/.Net driver version that supports MongoDB 7.0 and later. For complete documentation on compatibility between the C#/.Net driver and MongoDB, see the MongoDB compatibility matrix. We recommend that you upgrade to the latest version of the driver.
var client = new MongoClient("mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority"); var database = client.GetDatabase("<databaseName>");
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
MongoDB 7.0 이상 | 2.7 버전 이상 |
참고
Microsoft .NET Core 라이브러리 버전 2.1 이상 은 Linux 및 macOS에서 SNI TLS 확장을 지원. 이러한 플랫폼에서 이전 버전의 .NET Core를 사용하는 애플리케이션은 Atlas 무료 클러스터 또는 Flex 클러스터 에 연결할 수 없습니다.
이 요구 사항에 대해 자세히 학습하려면 이 .NET/corefx 이슈를 참조하세요.
참고
Atlas M0 무료 클러스터 또는 Flex 클러스터에 연결하려면 MongoDB 7.0 이상을 지원하는 Go 드라이버 버전을 사용해야 합니다. Go 드라이버와 MongoDB 간의 호환성에 대한 전체 문서는 MongoDB 호환성 매트릭스를 참조하세요. 드라이버를 최신 버전으로 업그레이드하는 것을 권장합니다.
uri := "mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority" clientOpts := options.Client().ApplyURI(uri).SetTimeout(10 * time.Second) client, err := mongo.Connect(clientOpts) if err != nil { log.Fatalf("Failed to connect to MongoDB: %v", err) } defer func() { if err = client.Disconnect(); err != nil { log.Fatalf("Failed to disconnect from MongoDB: %v", err) } }() ctx := context.Background() // Ping the primary if err := client.Ping(ctx, readpref.Primary()); err != nil { log.Fatalf("Failed to ping MongoDB: %v", err) }
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
MongoDB 7.0 이상 | 버전 1.0.0 이상 |
참고
To connect to an Atlas M0 cluster or a Flex cluster, you must use Java version 8 or later and use a Java driver version that supports MongoDB 7.0 or later. To learn more about compatibility between the Java driver and MongoDB, see the MongoDB compatibility matrix.
MongoClientURI uri = new MongoClientURI( "mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority"); MongoClient mongoClient = MongoClients.create(uri); MongoDatabase database = mongoClient.getDatabase("<databaseName>");
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
MongoDB 7.0 이상 | 3.8 버전 이상 |
참고
Atlas M0 무료 클러스터 또는 Flex 클러스터에 연결하려면 MongoDB 7.0 이상을 지원하는 Kotlin 드라이버 버전을 사용해야 합니다. Kotlin 드라이버와 MongoDB 간의 호환성에 대한 전체 문서는 MongoDB 호환성 매트릭스를 참조하세요. 드라이버를 최신 버전으로 업그레이드하는 것을 권장합니다.
val uri = "mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority" // Construct a ServerApi instance using the ServerApi.builder() method val serverApi = ServerApi.builder() .version(ServerApiVersion.V1) .build() val settings = MongoClientSettings.builder() .applyConnectionString(ConnectionString(uri)) .serverApi(serverApi) .build() // Create a new client and connect to the server val mongoClient = MongoClient.create(settings) val database = mongoClient.getDatabase("<databaseName>") try { // Send a ping to confirm a successful connection val command = Document("ping", BsonInt64(1)) val commandResult = database.runCommand(command) println("Pinged your deployment. You successfully connected to MongoDB!") } catch (me: MongoException) { System.err.println(me) }
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
MongoDB 7.0 이상 | 4.10 버전 이상 |
참고
Atlas M0 무료 클러스터 또는 Flex 클러스터에 연결하려면 MongoDB 7.0 이상을 지원하는 Node.js 드라이버 버전을 사용해야 합니다. Node.js 드라이버와 MongoDB 간의 호환성에 대한 전체 문서는 MongoDB 호환성 매트릭스를 참조하세요. 드라이버를 최신 버전으로 업그레이드하는 것을 권장합니다.
import mongodb from 'mongodb'; const MongoClient = mongodb.MongoClient; const uri = "mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority"; const client = new MongoClient(uri); client.connect(err => { const collection = client.db("<databaseName>").collection("<collectionName>"); // perform actions on the collection object client.close(); });
admin 이외의 데이터베이스에 연결하지만 여전히 admin 데이터베이스에 인증하려면 연결 문자열의 database 구성 요소를 업데이트합니다.
mongodb://username:password@host1:port1,...,hostN:portN/database?authSource=admin&...
예시
다음 연결 문자열은 cluster0 배포 및 test 데이터베이스 구성 요소를 지정하고 authSource=admin 옵션을 포함합니다.
var uriTestDb = "mongodb+srv://<db_username>:<db_password>@cluster0.mongodb.net/test?ssl=true&authSource=admin&w=majority"; MongoClient.connect(uriTestDb, function(err, db) { db.close(); });
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
MongoDB 7.0 이상 | 버전 3.1 이상 |
참고
To connect to an Atlas M0 Free cluster or a Flex cluster, you must use a PHP driver version that supports MongoDB 7.0 and later. For complete documentation on compatibility between the PHP driver and MongoDB, see the MongoDB compatibility matrix. We recommend that you upgrade to the latest version of the driver.
다음 예제에서는 저수준 PHP 드라이버에 대한 고수준 추상화를 제공하는 MongoDB PHP 라이브러리를 사용합니다.
$client = new MongoDB\Client( 'mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority'); $db = $client-><databaseName>;
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
MongoDB 7.0 이상 | PHPLIB 1.4 + mongodb-1.5. |
행동
MongoDB 드라이버는 클러스터 투표 또는 페일오버 이벤트 후 자동으로 서버 선택을 시도합니다. 기본적으로 드라이버는 첫 번째 서버 선택 시도가 실패하면 즉시 오류를 발생시킵니다. 다음 구성 설정은 서버 선택 루프에서 더 많은 시간을 소비하는 대신 Atlas 클러스터에 대한 애플리케이션 연결을 개선할 수 있습니다.
Set serverSelectionTryOnce to
falseto direct the driver to perform server selection up to the time limit defined byserverSelectionTimeoutMS.Lower the serverSelectionTimeoutMS to
15000from the default of30000. MongoDB elections typically take 10 seconds, but can be as fast as 5 seconds on Atlas. Setting this value to 15 seconds (15000milliseconds) covers the upper bound of election plus additional time for latency.
참고
To connect to an Atlas M0 cluster or a Flex cluster, you must use Python 2.7.9 or later and use a Python driver version that supports MongoDB 7.0 or later. To learn more about compatibility between the Python driver and MongoDB, see the MongoDB compatibility matrix.
import pymongo import dns # required for connecting with SRV client = pymongo.MongoClient("mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority") db = client.<databaseName>
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
MongoDB 7.0 이상 | 3.7 버전 이상 |
참고
macOS 및 Python 3.6 설치 관리자
https://www.python.org 의 macOS용 Python 3.6 설치 프로그램은 CA 인증서를 자동으로 설치하지 않습니다. CA 인증서를 설치하지 않으면 Atlas 에 대한 연결이 인증서 확인에 실패합니다.
https://www.python.org 에서 설치 프로그램을 실행하여 Python 3.6을(를) 설치합니다. Atlas 에 연결하기 전에 다음 스크립트 실행 최신 CA 번들을 설치해야 합니다.
open "/Applications/Python 3.6/Install Certificates.command"
macOS용 Python 3.6 설치 프로그램에 대한 자세한 내용은 https://www.python.org에서 확인할 수 있습니다. 관련 정보는 https://bugs.python.org/issue29065#msg283984에서 확인하세요. 이전 버전의 Python 및 다른 방법으로 설치된 Python 3.6 (예: Homebrew)은 영향을 받지 않습니다.
참고
Atlas M0 무료 클러스터 또는 Flex 클러스터에 연결하려면 MongoDB 7.0 이상을 지원하는 Ruby 드라이버 버전을 사용해야 합니다. Ruby 드라이버와 MongoDB 간의 호환성에 대한 전체 문서는 MongoDB 호환성 매트릭스를 참조하세요. 드라이버를 최신 버전으로 업그레이드하는 것을 권장합니다.
client = Mongo::Client.new('mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority')
admin 이외의 데이터베이스에 연결하지만 여전히 admin 데이터베이스에 인증하려면 연결 문자열의 database 구성 요소를 업데이트합니다.
mongodb://username:password@host1:port1,...,hostN:portN/database?authSource=admin&...
예시
다음 연결 문자열은 cluster0 배포 및 test 데이터베이스 구성 요소를 지정하고 authSource=admin 옵션을 포함합니다.
client = Mongo::Client.new('mongodb+srv://<db_username>:<db_password>@cluster0.mongodb.net/test?ssl=true&replicaSet=Mycluster0-shard-0&authSource=admin&w=majority')
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
MongoDB 7.0 이상 | 2.6 버전 이상 |
Mongoid 예시
production: # Configure available database clients. (required) clients: # Defines the default client. (required) default: # Defines the name of the default database that Mongoid can connect to. # (required). database: 'myDatabaseName' # Provides the hosts the default client can connect to. Must be an array # of host:port pairs. (required) hosts: - mycluster0-shard-00-00.mongodb.net:27017 - mycluster0-shard-00-01.mongodb.net:27017 - mycluster0-shard-00-02.mongodb.net:27017 options: # The name of the user for authentication. user: <username> # The password of the user for authentication. password: <password> # The database or source to authenticate the user against. If the database # specified above is not admin, admin MUST be specified here. auth_source: admin # All Atlas servers use SSL. (default: false) ssl: true
MongoDB 버전 | 최소 ODM 버전 |
|---|---|
MongoDB 7.0 이상 |
운전자 에서 사용하는 기본값 비동기 런타임은 tokio입니다. 다른 런타임을 사용하려면비동기 런타임 구성을 참조하세요.
참고
To connect to an Atlas M0 Free cluster or a Flex cluster, you must use a Rust driver version that supports MongoDB 7.0 and later. For complete documentation on compatibility between the Rust driver and MongoDB, see the MongoDB compatibility matrix. We recommend that you upgrade to the latest version of the driver.
use mongodb::{options::ClientOptions, Client}; async fn main() -> mongodb::error::Result<()> { let client_options = ClientOptions::parse( "mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority", ) .await?; let client = Client::with_options(client_options)?; let _database = client.database("<databaseName>"); // List the names of the databases in that cluster for db_name in client.list_database_names(None, None)? { println!("{}", db_name); } Ok(()) }
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
동기화 API를 활성화했는지 확인합니다. 자세한 내용은 동기화 API 활성화를 참조하세요.
참고
To connect to an Atlas M0 Free cluster or a Flex cluster, you must use a Rust driver version that supports MongoDB 7.0 and later. For complete documentation on compatibility between the Rust driver and MongoDB, see the MongoDB compatibility matrix. We recommend that you upgrade to the latest version of the driver.
use mongodb::{bson::doc, sync::Client}; fn main() -> mongodb::error::Result<()> { let client_options = ClientOptions::parse( "mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority", )?; // Ping the server to see if you can connect to the cluster client .database("admin") .run_command(doc! {"ping": 1}, None)?; println!("Connected successfully."); // List the names of the databases in that cluster for db_name in client.list_database_names(None, None)? { println!("{}", db_name); } Ok(()) }
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
참고
To connect to an Atlas M0 Free cluster or a Flex cluster, you must use a Scala driver version that supports MongoDB 7.0 and later. For complete documentation on compatibility between the Scala driver and MongoDB, see the MongoDB compatibility matrix. We recommend that you upgrade to the latest version of the driver.
val uri: String = "mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority" System.setProperty("org.mongodb.async.type", "netty") val client: MongoClient = MongoClient(uri) val db: MongoDatabase = client.getDatabase("<databaseName>")
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
참고
To connect to an Atlas M0 Free cluster or a Flex cluster, you must use a Swift driver version that supports MongoDB 7.0 and later. For complete documentation on compatibility between the Swift driver and MongoDB, see the MongoDB compatibility matrix. We recommend that you upgrade to the latest version of the driver.
import MongoSwift import NIO let elg = MultiThreadedEventLoopGroup(numberOfThreads: 4) let uri = "mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority" let client = try MongoClient( uri, using: elg ) defer { // clean up driver resources try? client.syncClose() cleanupMongoSwift() // shut down EventLoopGroup try? elg.syncShutdownGracefully() } // print a list of database names to confirm connection print(try client.listDatabaseNames().wait())
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
참고
To connect to an Atlas M0 Free cluster or a Flex cluster, you must use a Swift driver version that supports MongoDB 7.0 and later. For complete documentation on compatibility between the Swift driver and MongoDB, see the MongoDB compatibility matrix. We recommend that you upgrade to the latest version of the driver.
import MongoSwiftSync let uri = "mongodb+srv://<db_username>:<db_password>@<clusterName>.mongodb.net/?retryWrites=true&w=majority" let client = try MongoClient(uri) // print a list of database names to confirm connection print (try client.listDatabaseNames())
MongoDB 버전 | 권장 드라이버 버전 |
|---|---|
모두 | See the MongoDB compatibility matrix for the latest recommended driver versions. |
문제 해결
클러스터에 연결하는 데 문제가 있는 경우 연결 문제 해결을 참조하세요.