AI 에이전트의 경우: 문서 인덱스는 https://www.mongodb.com/ko-kr/docs/llms.txt에서 사용할 수 있으며, 모든 페이지의 마크다운 버전은 어떤 URL 경로에 .md를 추가하여 사용할 수 있습니다.
Docs Menu

db.getSiblingDB() (mongosh 메서드)

db.getSiblingDB(<database>)
Parameter
유형
설명

database

문자열

MongoDB 데이터베이스의 이름입니다.

반환합니다:

데이터베이스 객체입니다.

셸 환경에서 db 변수를 수정하지 않고 다른 데이터베이스를 반환하는 데 사용됩니다.

이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

참고

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

You can use db.getSiblingDB() as an alternative to the use <database> helper. This is particularly useful when writing scripts using mongosh where the use helper is not available.

users 및 records라는 두 개의 데이터베이스를 가진 MongoDB 인스턴스를 예로 들어 보겠습니다. active 컬렉션은 users 데이터베이스에 포함되어 있습니다. requests 컬렉션은 records 데이터베이스에 포함되어 있습니다.

이 작업은 db 객체가 users라는 데이터베이스를 가리키도록 설정한 다음, activeactive 컬렉션에 대해 document count를 반환합니다.

db = db.getSiblingDB('users')
db.active.countDocuments()

다음과 같은 작업 순서와 같이 서로 다른 데이터베이스를 참조하는 db 객체를 여러 개 생성할 수 있습니다.

users = db.getSiblingDB('users')
records = db.getSiblingDB('records')
users.active.countDocuments()
users.active.findOne()
records.requests.countDocuments()
records.requests.findOne()

이 작업은 두 개의 db 객체를 만듭니다. 각 db 객체는 서로 다른 데이터베이스 users 또는 records를 참조합니다.

각 데이터베이스에 대해 쿼리는 다음을 반환합니다.

해당 데이터베이스의 collection에서 반환합니다.

이 페이지 평가하기

이 페이지의 내용