Synopsis
The mongofiles utility makes it possible to manipulate files stored in your MongoDB instance in GridFS objects from the command line. It is particularly useful as it provides an interface between objects stored in your file system and GridFS.
Run mongofiles from the system command line, not the mongo shell.
버전 관리
mongofiles is now released separately from the MongoDB Server and uses its own versioning, with an initial version of 100.0.0. Previously, mongofiles was released alongside the MongoDB Server and used matching versioning.
This documentation is for version 100.19.0 of mongofiles.
호환성
MongoDB 서버 호환성
mongofiles version 100.19.0 supports the following versions of the MongoDB Server:
MongoDB 9.0
MongoDB 8.3
MongoDB 8.2
MongoDB 8.1
MongoDB 8.0
MongoDB 7.0
MongoDB 6.0
MongoDB 5.0
MongoDB 4.4
MongoDB 4.2
While mongofiles may work on earlier versions of MongoDB server, any such compatibility is not guaranteed.
플랫폼 지원
mongofiles version 100.19.0 is supported on the following platforms:
x86_64 | ARM64 | PPC64LE | s390x | |
|---|---|---|---|---|
Amazon Linux 2023 | ✓ | ✓ | ||
Amazon 2 | ✓ | ✓ | ||
Amazon 2013.03+ | ✓ | |||
Debian 12 | ✓ | |||
Debian 11 | ✓ | |||
Debian 10 | ✓ | |||
Debian 9 | ✓ | |||
RHEL / CentOS 9 | ✓ | ✓ | ✓ | ✓ |
RHEL / CentOS 8 | ✓ | ✓ | ✓ | |
RHEL / CentOS 7 | ✓ | ✓ | ✓ | |
RHEL / CentOS 6 | ✓ | |||
SUSE 15 | ✓ | |||
SUSE 12 | ✓ | |||
Ubuntu 24.04 | ✓ | ✓ | ||
Ubuntu 22.04 | ✓ | ✓ | ||
Ubuntu 20.04 | ✓ | ✓ | ||
Ubuntu 18.04 | ✓ | ✓ | ||
Ubuntu 16.04 | ✓ | ✓ | ✓ | |
Windows 11 이상 | ✓ | |||
Windows Server 2016 이상 | ✓ | |||
macOS 11 이상 | ✓ | ✓ | ||
macOS 10.12 - 10.15 | ✓ |
설치
The mongofiles tool is part of the MongoDB Database Tools package:
➤ Follow the Database Tools Installation Guide to install mongofiles.
구문
The mongofiles command has the following form:
mongofiles <options> <connection-string> <command> <filename or _id>
Run mongofiles from the system command line, not the mongo shell.
The components of the mongofiles command are:
Options. You may use one or more of these options to control the behavior of
mongofiles.Connection String. The connection string of themongod/mongosto connect to withmongofiles.Command. Use one of these commands to determine the action of
mongofiles.로컬 파일 시스템의 파일 이름 또는 GridFS 객체인 식별자입니다.
중요
For replica sets, mongofiles can only read from the set's primary.
필요한 액세스 권한
In order to connect to a mongod that enforces authorization with the --auth option, you must use the --username and --password options. The connecting user must possess, at a minimum:
행동
FIPS
mongofiles automatically creates FIPS-compliant connections to a mongod/mongos that is configured to use FIPS mode.
읽기 설정
By default, mongofiles uses read preference primary. To override the default, you can specify the read preference in the --readPreference command line option or in the --uri connection string.
If you specify read preference in the URI string and the --readPreference, the --readPreference value overrides the read preference specified in the URI string.
쓰기 고려
You can specify both the --writeConcern and the --uri connection string option. If write concern is specified using both options, the --writeConcern value overrides the write concern specified in the URI string.
옵션
--helpReturns information on the options and use of
mongofiles.
--quietRuns
mongofilesin a quiet mode that attempts to limit the amount of output.이 옵션은 다음과 같은 활동을 억제합니다.
데이터베이스 명령의 출력
복제 활동
연결 수락 이벤트
연결 종료 이벤트
--versionReturns the
mongofilesrelease number.
--config=<filename>버전 100 의 새로운 기능입니다.3.0.
Specifies the full path to a YAML configuration file that contains sensitive values for the following
mongofilesoptions:This is the recommended way to specify a password to
mongofiles, aside from specifying it through a password prompt. You can use any combination of the arguments in the file.구성 파일은 다음과 같은 형식을 취합니다:
password: <password> uri: mongodb://mongodb0.example.com:27017 sslPEMKeyPassword: <password> If you specify the
passwordoption without specifyinguri, you can specify the other components of the connection string by usingmongofilescommand line options, such as--usernameand--host.적절한 파일 시스템 권한으로 이 파일을 보호해야 합니다.
중요
--config옵션을 사용할 때는 다음과 같은 제한 사항 및 동작을 염두에 두세요.password필드를 제공하고uri필드에 충돌하는 비밀번호가 포함된 연결 문자열을 제공하면mongorestore에서 오류가 발생합니다.If you specify a configuration file with
--configand also use the--password,--uri, or--sslPEMKeyPasswordmongofilescommand line options, the command line option overrides the corresponding configuration file option.
--uri=<connectionString>따옴표로 묶인 MongoDB 배포의 확인 가능한 URI 연결 문자열을 지정합니다.
--uri="mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]" Starting with version
100.0ofmongofiles, the connection string may alternatively be provided as a positional parameter, without using the--urioption:mongofiles mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]] 연결 문자열은
mongodb://또는mongodb+srv://중 하나로 시작하기만 하면 명령줄의 어느 지점에서나 위치 매개변수로 지정할 수 있습니다. 예시:mongofiles --username joe --password secret1 mongodb://mongodb0.example.com:27017 --ssl Only one connection string can be provided. Attempting to include more than one, whether using the
--urioption or as a positional argument, will result in an error.연결 문자열의 구성 요소에 대한 자세한 내용은 연결 문자열 URI 형식 문서를 참조하세요.
참고
connection string의 일부 구성요소는--username및--password와 같은 자체 명시적 명령줄 옵션을 사용하여 지정할 수도 있습니다. 명시적 옵션을 사용하면서 연결 문자열을 제공하고 충돌하는 정보를 지정하면 오류가 발생합니다.참고
Ubuntu 에서
mongofiles를 사용하는 18 경우.,04cannot unmarshal DNS옵션과 함께 SRV 연결 문자열(mongodb+srv://형식)을 사용할 때--uri오류 메시지가 표시될 수 있습니다. 이 경우 다음 옵션 중 하나를 대신 사용합니다.the
--urioption with a non-SRV connection string (in the formmongodb://)--host옵션을 사용하여 직접 연결할 호스트를 지정하세요.
--host=<hostname><:port>Specifies a resolvable hostname for the
mongodthat holds your GridFS system. By defaultmongofilesattempts to connect to a MongoDB process running on the localhost port number27017.선택적으로 포트 번호를 지정하여 27017이 아닌 다른 포트에서 실행 중인 MongoDB 인스턴스를 연결할 수 있습니다.
또는
URI connection string에 호스트 이름을 직접 지정할 수도 있습니다.--host를 사용하면서 연결 문자열을 제공하고 충돌하는 정보를 지정하면 오류가 발생합니다.
--port=<port>기본값: 27017
MongoDB 인스턴스가 클라이언트 연결 수신을 대기하는 TCP 포트를 지정합니다.
또는
URI connection string에 직접 포트를 지정할 수도 있습니다.--port를 사용하면서 연결 문자열 제공하고 충돌하는 정보를 지정하면 오류가 발생합니다.
--sslEnables connection to a
mongodormongosthat has TLS/SSL support enabled.또는
URI connection string에서 직접 TLS/SSL 지원을 구성할 수도 있습니다. 연결 문자열을 제공하면서--ssl을 사용하고 상충하는 정보를 지정하면 오류가 발생합니다.TLS/SSL 및 MongoDB에 대한 자세한 내용은 TLS/SSL을 위한 mongod 및 mongos 구성 및 클라이언트를 위한 TLS/SSL 구성을 참조하세요.
--sslCAFile=<filename>인증 기관의 루트 인증서 체인이 포함된
.pem파일을 지정합니다. 상대 경로 또는 절대 경로를 사용하여.pem파일의 이름을 지정합니다.또는
URI connection string에 직접.pem파일을 지정할 수도 있습니다.--sslCAFile를 사용하면서 연결 문자열을 제공하고 충돌하는 정보를 지정하면 오류가 발생합니다.TLS/SSL 및 MongoDB에 대한 자세한 내용은 TLS/SSL을 위한 mongod 및 mongos 구성 및 클라이언트를 위한 TLS/SSL 구성을 참조하세요.
--sslPEMKeyFile=<filename>TLS/SSL 인증서와 키가 모두 포함되어 있는
.pem파일을 지정합니다. 상대 경로 또는 절대 경로를 사용해.pem파일의 이름을 지정합니다.This option is required when using the
--ssloption to connect to amongodormongosthat hasCAFileenabled withoutallowConnectionsWithoutCertificates.또는
URI connection string에 직접.pem파일을 지정할 수도 있습니다.--sslPEMKeyFile를 사용하면서 연결 문자열을 제공하고 충돌하는 정보를 지정하면 오류가 발생합니다.TLS/SSL 및 MongoDB에 대한 자세한 내용은 TLS/SSL을 위한 mongod 및 mongos 구성 및 클라이언트를 위한 TLS/SSL 구성을 참조하세요.
--sslPEMKeyPassword=<value>Specifies the password to de-crypt the certificate-key file (i.e.
--sslPEMKeyFile). Use the--sslPEMKeyPasswordoption only if the certificate-key file is encrypted. In all cases, themongofileswill redact the password from all logging and reporting output.If the private key in the PEM file is encrypted and you do not specify the
--sslPEMKeyPasswordoption, themongofileswill prompt for a passphrase. See TLS/SSL Certificate Passphrase.또는
URI connection string에 비밀번호를 직접 지정할 수도 있습니다.--sslPEMKeyPassword를 사용하면서 연결 문자열을 제공하고 충돌하는 정보를 지정하면 오류가 발생합니다.TLS/SSL 및 MongoDB에 대한 자세한 내용은 TLS/SSL을 위한 mongod 및 mongos 구성 및 클라이언트를 위한 TLS/SSL 구성을 참조하세요.
경고
일부 시스템에서는
--sslPEMKeyPassword옵션을 사용해 직접 제공된 비밀번호가 다른 사용자가 호출할 수 있는ps와 같은 시스템 상태 프로그램에 표시될 수 있습니다. 대신--config옵션을 사용하여 비밀번호가 포함된 설정 파일을 지정하는 것이 좋습니다.
--sslCRLFile=<filename>인증서 해지 목록이 포함된
.pem파일을 지정합니다. 상대 경로 또는 절대 경로를.pem파일의 이름을 지정합니다.TLS/SSL 및 MongoDB에 대한 자세한 내용은 TLS/SSL을 위한 mongod 및 mongos 구성 및 클라이언트를 위한 TLS/SSL 구성을 참조하세요.
--sslAllowInvalidCertificatesBypasses the validation checks for server certificates and allows the use of invalid certificates. When using the
allowInvalidCertificatessetting, MongoDB logs as a warning the use of the invalid certificate.경고
--sslAllowInvalidCertificates옵션은 사용할 수 있는 경우에도 가급적 사용하지 않는 것이 좋습니다.--sslAllowInvalidCertificates를 사용해야만 하는 경우, 침입이 불가능한 시스템에서만 옵션을 사용하세요.Connecting to a
mongodormongosinstance without validating server certificates is a potential security risk. If you only need to disable the validation of the hostname in the TLS/SSL certificates, see--sslAllowInvalidHostnames.또는
URI connection string에서 직접 인증서 유효성 검사 비활성화할 수도 있습니다.--sslAllowInvalidCertificates를 사용하면서 연결 문자열 제공하고 충돌하는 정보를 지정하면 오류가 발생합니다.TLS/SSL 및 MongoDB에 대한 자세한 내용은 TLS/SSL을 위한 mongod 및 mongos 구성 및 클라이언트를 위한 TLS/SSL 구성을 참조하세요.
--sslAllowInvalidHostnamesDisables the validation of the hostnames in TLS/SSL certificates. Allows
mongofilesto connect to MongoDB instances even if the hostname in their certificates do not match the specified hostname.또는
URI connection string에서 호스트 이름 유효성 검사를 비활성화할 수도 있습니다.--sslAllowInvalidHostnames를 사용하면서 연결 문자열을 제공하고 충돌하는 정보를 지정하면 오류가 발생합니다.TLS/SSL 및 MongoDB에 대한 자세한 내용은 TLS/SSL을 위한 mongod 및 mongos 구성 및 클라이언트를 위한 TLS/SSL 구성을 참조하세요.
--username=<username>, -u=<username>Specifies a username with which to authenticate to a MongoDB database that uses authentication. Use in conjunction with the
--passwordand--authenticationDatabaseoptions.또는
URI connection string에 직접 사용자 이름을 지정할 수도 있습니다.--username을 사용하면서 연결 문자열을 제공하고 충돌하는 정보를 지정하면 오류가 발생합니다.If connecting to a MongoDB Atlas cluster using the
MONGODB-AWSauthentication mechanism, you can specify your AWS access key ID in:이 필드,
the
connection string, orAWS_ACCESS_KEY_ID환경 변수.
각각의 예는 AWS IAM 자격 증명을 사용하여 MongoDB Atlas 클러스터에 연결하기를 참조하세요.
--password=<password>, -p=<password>Specifies a password with which to authenticate to a MongoDB database that uses authentication. Use in conjunction with the
--usernameand--authenticationDatabaseoptions.To prompt the user for the password, pass the
--usernameoption without--passwordor specify an empty string as the--passwordvalue, as in--password "".또는
URI connection string에 비밀번호를 직접 지정할 수도 있습니다.--password를 사용하면서 연결 문자열을 제공하고 충돌하는 정보를 지정하면 오류가 발생합니다.If connecting to a MongoDB Atlas cluster using the
MONGODB-AWSauthentication mechanism, you can specify your AWS secret access key in:이 필드,
the
connection string, orAWS_SECRET_ACCESS_KEY환경 변수.
각각의 예는 AWS IAM 자격 증명을 사용하여 MongoDB Atlas 클러스터에 연결하기를 참조하세요.
경고
일부 시스템에서는
--password옵션을 사용해 직접 제공된 비밀번호가 다른 사용자가 호출할 수 있는ps와 같은 시스템 상태 프로그램에 표시될 수 있습니다. 대신 다음을 고려해 보세요.--password옵션을 생략하여 대화형 비밀번호 프롬프트를 받거나--config옵션을 사용하여 비밀번호가 포함된 설정 파일을 지정합니다.
--awsSessionToken=<AWS Session Token>If connecting to a MongoDB Atlas cluster using the
MONGODB-AWSauthentication mechanism, and using session tokens in addition to your AWS access key ID and secret access key, you can specify your AWS session token in:이 필드,
the
AWS_SESSION_TOKENauthMechanismPropertiesparameter to theconnection string, orAWS_SESSION_TOKEN환경 변수.
각각의 예는 AWS IAM 자격 증명을 사용하여 MongoDB Atlas 클러스터에 연결하기를 참조하세요.
MONGODB-AWSauthentication mechanism을(를) 사용할 때만 유효합니다.
--authenticationDatabase=<dbname>Specifies the authentication database where the specified
--usernamehas been created. See Authentication Database.If you use the GSSAPI (Kerberos), PLAIN (LDAP SASL), or
MONGODB-AWSauthentication mechanisms, you must set--authenticationDatabaseto$external.또는
URI connection string에서 직접 인증 데이터베이스를 지정할 수도 있습니다.--authenticationDatabase를 사용하면서 연결 문자열을 제공하고 충돌하는 정보를 지정하면 오류가 발생합니다.
--authenticationMechanism=<name>기본값: SCRAM-SHA-1
Specifies the authentication mechanism the
mongofilesinstance uses to authenticate to themongodormongos.Changed in version 100.1.0:
Starting in version
100.1.0,mongofilesadds support for theMONGODB-AWSauthentication mechanism when connecting to a MongoDB Atlas cluster.값설명SHA- 해시 함수를 사용하는RFC 표준 솔티드 챌린지 응답 인증 메커니즘.5802 1
RFC 7677 standard Salted Challenge Response Authentication Mechanism using the SHA-256 hash function.
featureCompatibilityVersion이
4.0으로 설정되어야 합니다.MongoDB TLS/SSL 인증서 인증.
MONGODB-AWSMongoDB Atlas 클러스터 연결에 사용하기 위한 AWS IAM 자격 증명을 사용하는 외부 인증입니다. AWS IAM 자격 증명을 사용하여 MongoDB Atlas 클러스터에 연결하기를 참조하세요.
버전 100 의 새로운 기능입니다.1.0.
GSSAPI (Kerberos)
Kerberos를 사용한 외부 인증. 이 메커니즘은 MongoDB Enterprise에서만 사용할 수 있습니다.
PLAIN (LDAP SASL)
LDAP를 사용한 외부 인증.
PLAIN을 사용해 데이터베이스 내 사용자를 인증할 수도 있습니다.PLAIN은 비밀번호를 일반 텍스트로 전송합니다. 이 메커니즘은 MongoDB Enterprise에서만 사용할 수 있습니다.또는
URI connection string에서 직접 인증 메커니즘을 지정할 수도 있습니다.--authenticationMechanism를 사용하면서 연결 문자열을 제공하고 충돌하는 정보를 지정하면 오류가 발생합니다.
--gssapiServiceName=<serviceName>Specify the name of the service using GSSAPI/Kerberos. Only required if the service does not use the default name of
mongodb.이 옵션은 MongoDB Enterprise에서만 사용할 수 있습니다.
--gssapiHostName=<hostname>GSSAPI/Kerberos를 사용하여 서비스의 호스트 이름을 지정합니다. 시스템의 호스트 이름이 DNS에서 확인한 호스트 이름과 일치하지 않는 경우에만 필요합니다.
이 옵션은 MongoDB Enterprise에서만 사용할 수 있습니다.
--db=<database>, -d=<database>Specifies the name of the database on which to run the
mongofiles.또는
URI connection string에 직접 데이터베이스를 지정할 수도 있습니다.--db를 사용하면서 연결 문자열을 제공하고 충돌하는 정보를 지정하면 오류가 발생합니다.
--local=<filename>, -l=<filename>가져오기 및 넣기 작업에 사용할 파일의 로컬 파일 시스템 이름을 지정합니다.
In the mongofiles put and mongofiles get commands, the required
<filename>modifier refers to the name the object will have in GridFS.mongofilesassumes that this reflects the file's name on the local file system. This setting overrides this default.
--type=<MIME>Provides the ability to specify a MIME type to describe the file inserted into GridFS storage.
mongofilesomits this option in the default operation.mongofiles put 작업에만 사용합니다.
--replace, -r동일한 이름의 객체를 추가하는 대신 기존 GridFS 객체를 지정된 로컬 파일로 대체하기 위해 mongofiles put의 동작을 변경합니다.
기본 작업에서는 mongofiles put 옵션으로 파일을 덮어쓰지 않습니다.
--writeConcern=<document>기본값: 대다수(majority)
Specifies the write concern for each write operation that
mongofilesperforms.w 옵션을 사용하여 쓰기 고려를 문서로 지정합니다.
--writeConcern="{w:'majority'}" If the write concern is also included in the
--uri connection string, the command-line--writeConcernoverrides the write concern specified in the URI string.
--readPreference=<string|document>Default:
primarySpecifies the read preference for
mongofiles. The--readPreferenceoption can take:읽기 설정 모드만 지정하는 경우 문자열입니다:
--readPreference=secondary 따옴표로 묶인 문서를 통해 모드, 선택적 읽기 설정 태그 세트 및 선택적 maxStalenessSeconds를 지정할 수 있습니다.
--readPreference='{mode: "secondary", tagSets: [ { "region": "east" } ], maxStalenessSeconds: 120}' maxStalenessSeconds를 지정하는 경우 이 값은 보다 크거나 같아야 90 합니다.
mongofilesdefaults toprimaryread preference.If the read preference is also included in the
--uri connection string, the command-line--readPreferenceoverrides the read preference specified in the URI string.
명령.
list <prefix>GridFS 저장소에 있는 파일을 나열합니다.
list뒤에 지정된 문자 (예:<prefix>)의 경우 반환된 항목 목록을 해당 문자열로 시작하는 파일로 선택적으로 제한합니다.
search <string><string>의 일부와 일치하는 이름을 가진 GridFS 저장소의 파일을 나열합니다.
put <filename1[ filename2] ...>지정한 파일을 로컬 파일 시스템에서 GridFS 스토리지로 복사합니다. 여러 파일을 공백으로 구분된 목록으로 지정할 수 있습니다.
Each specified filename refers to the name the object will have in GridFS, and
mongofilesassumes that this reflects the name the file has on the local file system. If the local filename is different, use themongofiles --localoption.
get <filename1[ filename2] ...>지정한 파일을 GridFS 스토리지에서 로컬 파일 시스템으로 복사합니다.
Each specified filename refers to the name the object has in GridFS, and
mongofileswill use this filename when writing to the local file system.If specifying only one
filenameto thegetcommand, you can use the--localoption to specify a different local filename to write to, if desired. The--localoption cannot be used if specifying more than onefilenameto thegetcommand.참고
GridFS 스토리지에서 정규 표현식과 일치하는 파일을 복사하려면
get_regex명령을 대신 사용합니다.
get_id "<_id>"<_id>로 지정된 파일을 GridFS 저장소에서 로컬 파일 시스템으로 복사합니다.<_id>는 GridFS에 있는 객체의 확장 JSON_id를 참조합니다.get_id는<_id>에 대해 ObjectId 값 또는 비-ObjectId 값을 허용할 수 있습니다.mongofileswrites the file to the local file system using the file's filename in GridFS. To choose a different location for the file on the local file system, use the--localoption.
get_regex <regex> --regexOptions <regex-options>지정된
<regex>표현식과 일치하는 파일을 GridFS 스토리지에서 로컬 파일 시스템으로 복사합니다.get_regex명령은 UTF-8 지원이 포함된 펄(Perl) 호환 정규 표현식(" PCRE ") 버전 8.42를 사용합니다.You may optionally specify one or more
<regex-options>using the--regexOptionsflag. These can be any of the options supported by the $regex operator, which include settings such as case-insensitivity. Multiple options should be provided together without separators, e.g.--regexOptions simongofileswrites the file or files to the local file system using each file's matched filename in GridFS. You cannot use the--localoption with theget_regexcommand.
delete <filename>지정한 파일을 GridFS 스토리지에서 삭제합니다.
delete_id "<_id>"<_id>(으)로 지정된 파일을 GridFS 저장소에서 삭제합니다.delete_id는<_id>에 대해 ObjectId 값 또는 비-ObjectId 값을 받아들일 수 있습니다.
예시
Run mongofiles from the system command line, not the mongo shell.
To return a list of all files in a GridFS collection in the records database, use the following invocation at the system shell:
mongofiles -d=records list
This mongofiles instance will connect to the mongod instance running on the 27017 localhost interface to specify the same operation on a different port or hostname, and issue a command that resembles one of the following:
mongofiles --port=37017 -d=records list mongofiles --host=db1.example.net -d=records list mongofiles --host=db1.example.net --port=37017 -d=records list
Modify any of the following commands as needed if you're connecting the mongod instances on different ports or hosts.
32-corinth.lp 파일을 records 데이터베이스의 GridFS 컬렉션에 업로드하려면 다음 명령을 사용할 수 있습니다.
mongofiles -d=records put 32-corinth.lp
records 데이터베이스 내 해당 GridFS 컬렉션에서 32-corinth.lp 파일을 삭제하려면 다음 명령을 사용할 수 있습니다.
mongofiles -d=records delete 32-corinth.lp
records 데이터베이스 내 GridFS 컬렉션의 파일 중 이름에 corinth(이)가 포함된 파일을 검색하려면 다음 명령을 사용할 수 있습니다:
mongofiles -d=records search corinth
records 데이터베이스의 GridFS 컬렉션에서 이름이 32 문자열로 시작하는 모든 파일을 나열하려면 다음 명령을 사용할 수 있습니다:
mongofiles -d=records list 32
records 데이터베이스의 GridFS 컬렉션에서 32-corinth.lp이라는 파일을 불러오려면 다음 명령을 사용할 수 있습니다.
mongofiles -d=records get 32-corinth.lp
records 데이터베이스의 GridFS 컬렉션에서 이름이 32 문자열로 시작하고 .lp 문자열로 끝나는 모든 파일을 불러오려면 다음 명령을 사용할 수 있습니다:
mongofiles -d=records get_regex 32*.lp
records 데이터베이스의 GridFS 컬렉션에서 _id: ObjectId("56feac751f417d0357e7140f")인 파일을 불러오려면 다음 명령을 사용할 수 있습니다:
mongofiles -d=records get_id '{"$oid": "56feac751f417d0357e7140f"}'
_id 주위에 따옴표를 넣어야 합니다.
AWS IAM 자격 증명을 사용하여 MongoDB Atlas 클러스터에 연결하기
버전 100 의 새로운 기능입니다.1.0.
To connect to a MongoDB Atlas cluster which has been configured to support authentication via AWS IAM credentials, provide a connection string to mongofiles similar to the following:
mongofiles 'mongodb+srv://<aws access key id>:<aws secret access key>@cluster0.example.com/testdb?authSource=$external&authMechanism=MONGODB-AWS' <other options>
Connecting to Atlas using AWS IAM credentials in this manner uses the MONGODB-AWS authentication mechanism and the $external authSource, as shown in this example.
If using an AWS session token, as well, provide it with the AWS_SESSION_TOKEN authMechanismProperties value, as follows:
mongofiles 'mongodb+srv://<aws access key id>:<aws secret access key>@cluster0.example.com/testdb?authSource=$external&authMechanism=MONGODB-AWS&authMechanismProperties=AWS_SESSION_TOKEN:<aws session token>' <other options>
Alternatively, the AWS access key ID, secret access key, and optionally session token can each be provided outside of the connection string using the --username, --password, and --awsSessionToken options instead, like so:
mongofiles 'mongodb+srv://cluster0.example.com/testdb?authSource=$external&authMechanism=MONGODB-AWS' --username <aws access key id> --password <aws secret access key> --awsSessionToken <aws session token> <other options>
명령줄 매개변수로 제공되는 경우 이러한 세 가지 옵션에는 퍼센트 인코딩이 필요하지 않습니다.
You may also set these credentials on your platform using standard AWS IAM environment variables. mongofiles checks for the following environment variables when you use the MONGODB-AWS authentication mechanism:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_SESSION_TOKEN
설정된 경우 이러한 자격 증명은 연결 문자열이나 명시적 옵션을 통해 지정할 필요가 없습니다.
참고
AWS 환경 변수를 사용하여 이러한 값을 지정하기로 선택한 경우 이러한 자격 증명에 해당하는 명시적 또는 연결 문자열 옵션과 조합하여 사용할 수 없습니다. 액세스 키 ID 및 비밀 액세스 키(사용 중인 경우 세션 토큰도 함께 필요)에 환경 변수를 사용하거나 또는 명시적 또는 연결 문자열 옵션을 사용하여 각각을 지정합니다.
다음 예시에서는 bash 셸에서 이러한 환경 변수를 설정합니다.
export AWS_ACCESS_KEY_ID='<aws access key id>' export AWS_SECRET_ACCESS_KEY='<aws secret access key>' export AWS_SESSION_TOKEN='<aws session token>'
다른 셸에서 환경 변수를 설정하는 구문은 다를 수 있습니다. 자세한 내용은 사용 중인 플랫폼의 설명서를 참조하세요.
다음 명령어로 이러한 환경 변수가 설정되었는지 확인할 수 있습니다.
env | grep AWS
설정이 완료되면 다음 예시에서는 이러한 환경 변수를 사용하여 MongoDB Atlas 클러스터에 연결합니다.
mongofiles 'mongodb+srv://cluster0.example.com/testdb?authSource=$external&authMechanism=MONGODB-AWS' <other options>