문서 메뉴
문서 홈
/ /
Atlas App Services
/

유선 프로토콜

이 페이지의 내용

  • 개요
  • 호환되는 클라이언트
  • 연결 문자열
  • 자격 증명
  • 부위
  • 매개변수
  • 유선 프로토콜 연결 활성화
  • 데이터 소스 구성 화면으로 이동
  • 클러스터에 대한 연결 문자열 활성화
  • 인증 방법 선택
  • 앱의 최신 버전 가져오기
  • 클러스터에 유선 프로토콜 활성화
  • 업데이트된 데이터 소스 구성 배포
  • 유선 프로토콜을 통한 연결
  • 연결 string을 사용하여 Atlas App Services에 연결
  • 데이터 읽기 및 수정
  • 함수 호출
  • 서비스 작업 호출 [사용 중단됨]
  • 로그인한 사용자 데이터 가져오기

Atlas App Services는 기본적으로 MongoDB 유선 프로토콜의 하위 집합을 구현하며, 이를 통해 표준 MongoDB 드라이버 및 도구를 사용하여 연결된 MongoDB Atlas 데이터 소스 중 하나를 통해 앱에 연결할 수 있습니다. 클라이언트는 특수 App Services 연결 문자열 을 사용하여 연결하고 요청을 보냅니다. App Services는 역할 기반 데이터 액세스 규칙, 함수서비스 작업을 포함하여 대부분의 클라이언트 기능을 유선 프로토콜을 통해 지원합니다.

이는 현재 Realm SDK가 없는 언어에 적합합니다. 여기에 있는 예제는 Python, C++11 및 Mongo Shell에 대한 것입니다. appName 연결 문자열 매개변수를 지원하는 모든 MongoDB 드라이버 는 유선 프로토콜을 사용하여 App Services에 연결할 수 있습니다.

참고

다음 도구 및 드라이버를 사용하면 연결 문자열을 통해 App Services와 통신할 수 있습니다.

  • mongo shell 의 4.0+ 버전입니다.

  • appName 연결 문자열 매개변수를 지원하는 모든 MongoDB 드라이버입니다. 모든 공식 MongoDB 드라이버는 현재 릴리스에서 이 매개변수를 지원합니다.

참고

유선 프로토콜을 통해 App Services에 연결하면 MongoDB 서비스 의 전체 기능에 액세스할 수 있습니다. 그러나 App Services는 표준 도구 및 클라이언트에서 사용할 수 있는 모든 작업 및 기능을 지원하지 않습니다. 자세한 내용은 MongoDB 서비스 제한 사항을 참조하세요.

유선 프로토콜을 통해 App Services에 연결하려면 애플리케이션 사용자 에 대한 자격 증명과 애플리케이션별 appName 쿼리 매개변수를 포함하는 MongoDB 연결 문자열 을 구성해야 합니다.

중요

URL 인코딩

URL 인코딩 을(를) 해야 합니다. 연결 문자열을 사용하여 Atlas App Services에 연결할 수 있습니다. Atlas App Services UI의 연결 문자열은 기본적으로 올바르게 인코딩됩니다.

App Services 연결 문자열의 형식은 다음과 같습니다.

mongodb://<credentials>@<region>.services.cloud.mongodb.com:27020/?<parameters>

유선 프로토콜을 통해 실행하는 모든 작업은 연결 문자열에서 지정한 특정 애플리케이션 사용자의 컨텍스트에서 실행됩니다. 사용자는 다음 인증 제공자 중 하나에 등록되어 있어야 합니다.

연결 문자열 자격 증명의 내용은 사용자가 등록되어 있는 인증 제공자에 따라 다릅니다.

형식
<email>:<password>
필드
<email>
사용자의 등록된 이메일 주소입니다.
<password>
사용자의 비밀번호입니다.
예제
joe.mango@company.com:SuperSecretPassword123
형식
_:<apiKey>
필드
<apiKey>
활성 애플리케이션 API 키입니다.
예제
_:tOSJwYhLLam1qTAwP8rZ5M9BiHfn69w5xrya52dYeOv1PdTlD68i8gKOaN0Wy24z
형식
_:<customAuthToken>
필드
<customAuthToken>
사용자 지정 인증 JSON Web Token입니다.
예제
_:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.
SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

연결 문자열은 앱이 호스팅되는 배포 리전 과 클라우드 제공자를 지정해야 합니다.

글로벌 앱은 global 리전을 사용합니다.

mongodb://<credentials>@global.services.cloud.mongodb.com:27020/?<parameters>

로컬 앱은 <region>.<cloud> 형식을 사용하여 클라우드 제공자와 리전 이름을 지정합니다. 예를 들어 aws-us-east-1 에 배포된 앱은 다음 연결 문자열을 사용합니다.

mongodb://<credentials>@us-east-1.aws.services.cloud.mongodb.com:27020/?<parameters>

Atlas App Services에는 연결하려는 string 애플리케이션과 사용자가 제공하는 자격 증명 과 연결된 인증 제공자를 식별하는 특정 연결 옵션이 필요합니다.

App Services 연결 문자열에는 다음과 같은 쿼리 매개 변수가 있습니다.

매개 변수
설명
authMechanism
이 매개변수는 항상 PLAIN 로 설정해야 합니다.
authSource
이 매개변수는 항상 $external 로 설정해야 합니다.
appName

연결하려는 애플리케이션, MongoDB 서비스 및 인증 제공자를 고유하게 식별합니다.

appName 매개변수의 형식은 다음과 같습니다.

<app id>:<service>:<provider>
<app id>
앱의 App ID .
<service>
연결하려는 MongoDB 서비스의 이름입니다. 이 값은 항상 mongodb-atlas 입니다.
<provider>

자격 증명을 제공한 인증 제공자 입니다 .

유효한 값:

  • local-userpass

  • api-key

  • custom-token

연결 문자열을 사용하여 App Services App에 연결하려면 먼저 연결된 클러스터에 대해 유선 프로토콜 연결을 활성화해야 합니다.

1

왼쪽 탐색 메뉴의 Manage 섹션에서 Linked Data Sources 을 클릭합니다.

데이터 소스 목록에서 유선 프로토콜 연결을 활성화할 클러스터를 선택합니다.

2

MongoDB Connection String 의 토글을 Enabled 로 설정합니다. 표시되는 인증 방법 섹션에서 유선 프로토콜 연결을 인증할 방법을 선택하고 구성합니다.

UI에서 유선 프로토콜 활성화 토글
3
1

App Services CLI 를 사용하여 MongoDB 유선 프로토콜 연결을 활성화하려면 애플리케이션 구성 파일의 로컬 복사본이 필요합니다.

최신 버전의 앱의 로컬 사본을 가져오려면 다음을 실행하세요.

appservices pull --remote="<Your App ID>"

Realm UI의 Deploy > Export App 화면에서 애플리케이션의 구성 파일 사본을 다운로드할 수도 있습니다.

2

연결된 클러스터에 대해 유선 프로토콜 연결을 활성화하려면 클러스터의 config.json 파일을 열고 config.wireProtocolEnabled 값을 true 로 설정합니다.

{
"name": "mongodb-atlas",
"type": "mongodb-atlas",
"config": {
"wireProtocolEnabled": true,
...
}
}
3

config.json 에서 클러스터에 대한 유선 프로토콜 연결을 활성화한 후에는 구성을 원격 앱에 푸시할 수 있습니다. App Services CLI는 푸시 시 업데이트를 즉시 배포합니다.

appservices push --remote="<Your App ID>"

유선 프로토콜을 통해 Atlas App Services에 연결하려면 다음과 같이 인코딩된 URL을 전달합니다. 일반 연결 문자열과 마찬가지로 클라이언트를 만들 때 Atlas App Services 연결 string 을 생성 string.

$ mongo "mongodb://<user>:<password>@services.cloud.mongodb.com:27020/?authMechanism=PLAIN&authSource=%24external&ssl=true&appName=realm-application-abcde:mongodb-atlas:local-userpass"
mongocxx::instance instance{};
mongocxx::uri uri("mongodb://<user>:<password>@services.cloud.mongodb.com:27020/?authMechanism=PLAIN&authSource=%24external&ssl=true&appName=realm-application-abcde:mongodb-atlas:local-userpass");
mongocxx::client client(uri);
client = pymongo.MongoClient("mongodb://<user>:<password>@services.cloud.mongodb.com:27020/?authMechanism=PLAIN&authSource=%24external&ssl=true&appName=realm-application-abcde:mongodb-atlas:local-userpass")

유선 프로토콜을 통해 Atlas App Services에 연결되어 있는 동안 표준 MongoDB CRUD 작업을 사용할 수 있습니다. Atlas App Services는 연결 자격 증명에 지정된 인증된 사용자의 string 컨텍스트에 있는 모든 쿼리에 역할 기반 데이터 액세스 규칙 을 적용합니다 .

> use HR
> db.employees.findOne();
{
"_id": ObjectId("5ae782e48f25b9dc5c51c4a5"),
"employeeId": 854271626,
"name": {
"first": "Lucas",
"last": "Lewis"
},
"role": "PM",
"salary": 200000,
"email": "Lucas.Lewis.0271@company.com",
"password": "<password>",
"manager": {
"id": 328892725,
"email": "Daniel.Wilson.0474@company.com",
"name": {
"first": "Daniel",
"last": "Wilson"
}
}
}
mongocxx::database db = client["HR"];
mongocxx::collection employees = db["employees"];
bsoncxx::stdx::optional<bsoncxx::document::value> result =
collection.find_one({});
if(result) {
std::cout << bsoncxx::to_json(result) << "\n";
}
>>> db = client["HR"]
>>> employee = db["employees"].find_one();
>>> pprint(employee)
{'_id': ObjectId('5ae782e48f25b9dc5c51c4a5'),
'email': 'Lucas.Lewis.0271@company.com',
'employeeId': 854271626.0,
'manager': {'email': 'Daniel.Wilson.0474@company.com',
'id': 328892725.0,
'name': {'first': 'Daniel', 'last': 'Wilson'}},
'name': {'first': 'Lucas', 'last': 'Lewis'},
'password': '<password>',
'role': 'PM',
'salary': 200000}

callFunction 데이터베이스 명령을 사용하여 함수를 호출할 수 있습니다.

명령
설명
프로토타입
callFunction
지정된 함수 를 호출하고 결과를 반환합니다.
{
callFunction: <function name>,
arguments: [<arg1>, <arg2>, ...]
}
> db.runCommand({
... callFunction: "getEmployeeById",
... arguments: ["5ae782e48f25b9dc5c51c4a5"]
...});
{
"ok" : 1,
"response" : {
"_id": ObjectId("5ae782e48f25b9dc5c51c4a5"),
"employeeId": 854271626,
"name": {
"first": "Lucas",
"last": "Lewis"
},
"role": "PM",
"salary": 200000,
"email": "Lucas.Lewis.0271@company.com",
"password": "<password>",
"manager": {
"id": 328892725,
"email": "Daniel.Wilson.0474@company.com",
"name": {
"first": "Daniel",
"last": "Wilson"
}
}
}
}
db.runCommand({
callFunction: "getEmployeeById",
arguments: ["5ae782e48f25b9dc5c51c4a5"]
});
>>> function_result = db.command("callFunction", "getEmployeeById",
... arguments=["5ae782e48f25b9dc5c51c4a5"]
...)
>>> pprint.pprint(function_result)
{'ok': 1,
'response': {'_id': ObjectId('5ae782e48f25b9dc5c51c4a5'),
'email': 'Lucas.Lewis.0271@company.com',
'employeeId': 854271626.0,
'manager': {'email': 'Daniel.Wilson.0474@company.com',
'id': 328892725.0,
'name': {'first': 'Daniel', 'last': 'Wilson'}},
'name': {'first': 'Lucas', 'last': 'Lewis'},
'password': '<password>',
'role': 'PM',
'salary': 200000}}

callServiceFunction 데이터베이스 명령을 사용하여 서비스 작업을 호출할 수 있습니다.

명령
설명
프로토타입
callServiceFunction
지정된 서비스 작업 을 호출하고 결과를 반환합니다.
{
callServiceFunction: <function name>,
service: <service name>,
arguments: [<arg1>, <arg2>, ...]
}
> db.runCommand({
... callServiceFunction: "get",
... service: "http",
... arguments: [{ url: "https://jsonplaceholder.typicode.com/todos/1" }]
... });
{
"ok" : 1,
"response" : {
"status" : "200 OK",
"statusCode" : 200,
"contentLength" : NumberLong(-1),
"headers" : {
"Content-Type" : ["application/json; charset=utf-8"],
"Connection" : ["keep-alive"],
"Vary" : ["Origin, Accept-Encoding"],
"X-Content-Type-Options" : ["nosniff"],
"Via" : ["1.1 vegur"],
"X-Powered-By" : ["Express"],
"Cf-Cache-Status" : ["HIT"],
"Expect-Ct" : ["max-age=604800, report-uri=\"https://example.com/cdn-cgi/beacon/expect-ct\""],
"Set-Cookie" : ["__cfduid=d7f650e765d41beb7598ce2ab62d0c0191536867096; expires=Fri, 13-Sep-19 19:31:36 GMT; path=/; domain=.typicode.com; HttpOnly"],
"Access-Control-Allow-Credentials" : ["true"],
"Cache-Control" : ["public, max-age=14400"],
"Pragma" : ["no-cache"],
"Etag" : ["W/\"53-hfEnumeNh6YirfjyjaujcOPPT+s\""],
"Server" : ["example.com"],
"Cf-Ray" : ["459d08f88e1e56db-IAD"],
"Date" : ["Thu, 13 Sep 2018 19:31:36 GMT"],
"Expires" : ["Thu, 13 Sep 2018 23:31:36 GMT"]
},
"cookies" : {
"__cfduid" : {
"value" : "d7f650e765d41beb7598ce2ab62d0c0191536867096",
"path" : "/",
"domain" : ".typicode.com",
"expires" : "Mon, 01 Jan 0001 00:00:00 GMT",
"maxAge" : 0,
"secure" : false,
"httpOnly" : true
}
},
"body" : BinData(0,"ewogICJ1c2VySWQiOiAxLAogICJpZCI6IDEsCiAgInRpdGxlIjogImRlbGVjdHVzIGF1dCBhdXRlbSIsCiAgImNvbXBsZXRlZCI6IGZhbHNlCn0=")
}
}
db.runCommand({
callServiceFunction: "get",
service: "http",
arguments: [{ url: "https://jsonplaceholder.typicode.com/todos/1" }]
});
>>> result = db.command("callServiceFunction", "get",
... service="http",
... arguments=[{"url": "https://jsonplaceholder.typicode.com/todos/1"}]
...)
>>> pprint.pprint(result)
{'ok': 1,
'response': {'body': b'{\n "userId": 1,\n "id": 1,\n "title": "delectus aut'
b' autem",\n "completed": false\n}',
'contentLength': -1,
'cookies': {'__cfduid': {'domain': '.typicode.com',
'expires': 'Mon, 01 Jan 0001 00:00:00 '
'GMT',
'httpOnly': True,
'maxAge': 0,
'path': '/',
'secure': False,
'value': 'd4b10004e96ca7fee0be03dceebaf2ab71536866400'}},
'headers': {'Access-Control-Allow-Credentials': ['true'],
'Cache-Control': ['public, max-age=14400'],
'Cf-Cache-Status': ['HIT'],
'Cf-Ray': ['459cf7fc7e20c1bd-IAD'],
'Connection': ['keep-alive'],
'Content-Type': ['application/json; charset=utf-8'],
'Date': ['Thu, 13 Sep 2018 19:20:00 GMT'],
'Etag': ['W/"53-hfEnumeNh6YirfjyjaujcOPPT+s"'],
'Expect-Ct': ['max-age=604800, '
'report-uri="https://example.com/cdn-cgi/beacon/expect-ct"'],
'Expires': ['Thu, 13 Sep 2018 23:20:00 GMT'],
'Pragma': ['no-cache'],
'Server': ['example.com'],
'Set-Cookie': ['__cfduid=d4b10004e96ca7fee0be03dceebaf2ab71536866400; '
'expires=Fri, 13-Sep-19 19:20:00 GMT; '
'path=/; domain=.typicode.com; '
'HttpOnly'],
'Vary': ['Origin, Accept-Encoding'],
'Via': ['1.1 vegur'],
'X-Content-Type-Options': ['nosniff'],
'X-Powered-By': ['Express']},
'status': '200 OK',
'statusCode': 200}}

userProfile 데이터베이스 명령을 사용하여 인증된 사용자의 사용자 객체 를 가져올 수 있습니다.

명령
설명
프로토타입
userProfile
인증된 사용자의 사용자 객체 를 반환합니다.
{
userProfile: 1
}
> db.runCommand({ userProfile: 1 });
{
"ok" : 1,
"profile" : {
"userid" : "5ad7a79e8f25b975898d77b8",
"domainid" : ObjectId("5ad7a69746224c054067c8b1"),
"identities" : [
{
}
],
"data" : "{\"email\":\"joe.mango@company.com\"}",
"type" : "normal",
"roleassignments" : [ ]
}
}
db.runCommand({ userProfile: 1 });
>>> result = db.command("userProfile", 1)
>>> pprint.pprint(result)
{'ok': 1,
'profile': {'data': '{"email":"joe.mango@company.com"}',
'domainid': ObjectId('5ad7a69746224c054067c8b1'),
'identities': [{}],
'roleassignments': [],
'type': 'normal',
'userid': '5ad7a79e8f25b975898d77b8'}}

돌아가기

읽기 설정

다음

문서 미리보기