문서 메뉴
문서 홈
/
MongoDB Shell

mongosh 도움말

이 페이지의 내용

  • 명령줄 도움말
  • mongosh 셸 도움말
  • 데이터베이스 도움말
  • 컬렉션 도움말
  • 커서 도움말
  • BSON 클래스 도움말
  • 명령 도우미

이 문서는 mongosh에서 제공되는 도움말에 대한 개요를 제공합니다.

mongosh에서 도움말에 액세스할 경우 .help().help 구문을 교차하여 사용할 수 있습니다.

mongosh 실행 파일을 실행하고 --help 배포서버에 연결하기 위한 옵션은 명령줄에서 확인 가능합니다.

mongosh --help

2mongosh에서 이용 가능한 명령 목록을 확인하려면 mongosh를 실행 중인 콘솔에 help를 입력합니다.

help

mongosh 콘솔 내부에서 데이터베이스 수준 정보를 확인할 수 있습니다.

기본적으로 mongosh는 프롬프트에 현재 데이터베이스를 표시합니다. db 명령을 실행하여 현재 데이터베이스를 확인할 수도 있습니다.

db

서버에서 사용할 수 있는 데이터베이스의 목록을 보려면 show dbs 명령을 사용하세요.

show dbs

show databases show dbs의 별칭입니다.

데이터베이스 목록은 액세스 권한 부여에 따라 변경됩니다. 데이터베이스 보기에 대한 액세스 제한에 대한 자세한 내용은 listDatabases 를 참조하세요.

db 객체에 사용할 수 있는 데이터베이스 메서드 목록을 보려면 db.help() 를 실행합니다.

db.help()

출력은 다음의 축약된 목록과 유사합니다.

Database Class:
getMongo Returns the current database connection
getName Returns the name of the DB
getCollectionNames Returns an array containing the names of all collections in the current database.
getCollectionInfos Returns an array of documents with collection information, i.e. collection name and options, for the current database.
runCommand Runs an arbitrary command on the database.
adminCommand Runs an arbitrary command against the admin database.
...

mongosh 에서 특정 데이터베이스 메서드에 대한 도움말을 보려면 db.<method name> 을 입력한 다음 .help 또는 .help() 을 입력합니다. 다음 예시에서는 db.adminCommand() 메서드에 대한 도움말을 반환합니다.

db.adminCommand.help()

출력은 다음과 유사합니다.

db.adminCommand({ serverStatus: 1 }):
Runs an arbitrary command against the admin database.
For more information on usage: https://www.mongodb.com/ko-kr/docs/manual/reference/method/db.adminCommand

mongosh 에서 데이터베이스 메서드에 대한 추가 사용법 세부 정보를 보려면 괄호(()) 없이 db.<method name> 을 입력합니다. 다음 예시에서는 db.adminCommand() 메서드에 대한 세부 정보를 반환합니다.

db.adminCommand

출력은 다음과 유사합니다.

[Function: adminCommand] AsyncFunction {
apiVersions: [ 1, Infinity ],
serverVersions: [ '3.4.0', '999.999.999' ],
returnsPromise: true,
topologies: [ 'ReplSet', 'Sharded', 'LoadBalanced', 'Standalone' ],
returnType: { type: 'unknown', attributes: {} },
deprecated: false,
platforms: [ 0, 1, 2 ],
isDirectShellCommand: false,
acceptsRawInput: false,
shellCommandCompleter: undefined,
help: [Function (anonymous)] Help
}

mongosh 내에서 컬렉션 수준의 정보를 확인할 수 있습니다.

이러한 도움말 메서드에서는 컬렉션 이름 <collection>를 사용할 수 있지만 일반 용어인 '컬렉션'이나 존재하지 않는 컬렉션 이름을 사용할 수도 있습니다.

현재 데이터베이스의 컬렉션 목록을 보려면 show collections 명령을 사용합니다.

show collections

show collections 출력은 컬렉션이 time series 컬렉션 인지 읽기 전용 보기인지를 나타냅니다.

managementFeedback [view]
survey
weather [time-series]
system.buckets.weather
system.views

앞의 예시에서

  • managementFeedback 은(는) 입니다.

  • weather time-series입니다.

  • survey 컬렉션입니다.

  • system.buckets.weatherweather time-series를 지원하는 시스템 생성 컬렉션입니다.

  • system.views 은(는) 다른 컬렉션 보기를 지원하는 시스템 생성 컬렉션입니다.

컬렉션 객체에서 사용할 수 있는 메서드 목록을 확인하려면 db.<collection>.help() 메서드를 사용합니다.

db.collection.help()

<collection> 은 기존 또는 존재하지 않는 컬렉션의 이름일 수 있습니다.

출력은 다음의 축약된 목록과 유사합니다.

Collection Class:
aggregate Calculates aggregate values for the data in a collection or a view.
bulkWrite Performs multiple write operations with controls for order of execution.
count Returns the count of documents that would match a find() query for the collection or view.
countDocuments Returns the count of documents that match the query for a collection or view.
deleteMany Removes all documents that match the filter from a collection.
deleteOne Removes a single document from a collection.
...

mongosh에서 특정 컬렉션에 대한 도움말을 확인하려면 db.<collection>.<method name> 를 사용하고 그 다음 .help 또는 .help()를 사용합니다.

다음 예시에서는 db.collection.insertOne() 에 대한 도움말을 표시합니다.

db.collection.insertOne.help()

출력은 다음과 유사합니다.

db.collection.insertOne(document, options):
Inserts a document into a collection.
For more information on usage: https://www.mongodb.com/ko-kr/docs/manual/reference/method/db.collection.insertOne

컬렉션 메서드에 대한 추가 상세 정보를 확인하려면 괄호(()) 없이 컬렉션 이름 db.<collection>.<method>를 입력합니다.

다음 예에서는 insertOne() 메서드에 대한 세부 정보를 반환합니다.

db.collection.insertOne

출력은 다음과 유사합니다.

[Function: insertOne] AsyncFunction {
apiVersions: [ 1, Infinity ],
serverVersions: [ '3.2.0', '999.999.999' ],
returnsPromise: true,
topologies: [ 'ReplSet', 'Sharded', 'LoadBalanced', 'Standalone' ],
returnType: { type: 'unknown', attributes: {} },
deprecated: false,
platforms: [ 0, 1, 2 ],
isDirectShellCommand: false,
acceptsRawInput: false,
shellCommandCompleter: undefined,
help: [Function (anonymous)] Help
}

을(를) 사용하는 find() 읽기 작업 을수정하려면 커서 메서드를 사용합니다.

이용 가능한 수정자 및 커서 처리 방법을 나열하려면 db.collection.find().help() 명령을 사용합니다.

db.collection.find().help()

이 도움말 호출은 컬렉션 이름 <collection>를 허용하지만 일반 용어인 '컬렉션' 또는 존재하지 않는 컬렉션도 사용할 수 있습니다.

커서를 처리할 수 있는 몇 가지 유용한 메서드는 다음과 같습니다.

  • hasNext() 커서에 추가 문서가 있는지 확인합니다.

  • next() 다음 문서를 반환하고 커서 위치를 하나씩 앞으로 이동합니다.

  • forEach(<function>) 은 커서가 반환한 각 문서에 <function> 를 적용합니다.

사용 가능한 커서 메서드 목록은 커서를 참조하세요 .

mongosh BSON 클래스에 대한 도움말 메서드를 제공합니다. 도움말 메서드는 BSON 클래스에 대한 간략한 개요와 자세한 정보가 포함된 링크를 제공합니다.

BSON 클래스 도움말에 액세스하려면 클래스 이름이나 인스턴스화된 클래스 인스턴스에서 .help()를 실행합니다.

<BSON class>.help()
// or
<BSON class>().help()

예를 들어, ObjectId BSON 클래스에 대한 도움말을 보려면 다음 명령 중 하나를 실행합니다.

ObjectId.help()
ObjectId().help()

mongosh .help() 메서드 모두에 대해 동일한 출력을 반환합니다.

The ObjectId BSON Class:
For more information on usage: https://mongodb.github.io/node-mongodb-native/3.6/api/ObjectID.html

mongosh 는 다음 BSON 클래스에 대한 도움말 메서드를 제공합니다.

  • BinData

  • Code

  • DBRef

  • MinKey

  • MaxKey

  • NumberDecimal

  • NumberInt

  • NumberLong

  • ObjectId

  • Symbol (지원 중단됨)

  • Timestamp

mongosh 다음과 같은 메서드와 명령을 제공하여 특정 데이터베이스 명령을 래핑하고 배포서버에 대한 정보를 획득합니다.

도움말 메서드 및 명령
설명
db.help()
데이터베이스 메서드 도움말을 표시합니다.
db.<collection>.help()
컬렉션 메서드 도움말을 표시합니다. <collection>는 기존 컬렉션 또는 존재하지 않는 컬렉션의 이름일 수 있습니다.
help
도움말을 표시합니다.
show collections
현재 데이터베이스의 모든 컬렉션 목록을 표시합니다.
show dbs

서버의 모든 데이터베이스 목록을 표시합니다.

참고

show dbs 은(는) show databases의 동의어입니다.

show log <name>

지정된 로거 이름에 해당하는 로그인 메모리의 마지막 세그먼트를 표시합니다. <name>를 지정하지 않으면 명령의 기본값은 global입니다.

startupWarning 로그를 표시하려면 다음을 실행합니다.

show log startupWarnings
show logs
액세스 가능한 로거 이름을 표시합니다. 셸 로그 조회에서 확인 가능합니다.
show profile
1 밀리초 이상 소요된 가장 최근 작업 5건을 표시합니다. 자세한 내용은 데이터베이스 프로파일러 에 대한 설명서를 참조하세요.
show roles
현재 데이터베이스에 대해 사용자 정의 및 기본 제공 역할 목록을 모두 표시합니다.
show tables
현재 데이터베이스에 있는 컬렉션 목록을 표시합니다. show collections에서 확인 가능합니다.
show users
현재 데이터베이스의 사용자 목록을 표시합니다.
← 릴리스 노트