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

db.getCollection() (mongosh 메서드)

db.getCollection(name)

Returns a collection or a view object that is functionally equivalent to using the db.<collectionName> syntax. The method is useful for a collection or a view whose name might interact with mongosh itself, such as names that begin with _ or that match a database shell method.

The db.getCollection() method has the following parameter:

Parameter
유형
설명

name

문자열

컬렉션의 이름입니다.

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

  • MongoDB Atlas: 클라우드에서의 MongoDB 배포를 위한 완전 관리형 서비스

참고

이 명령은 모든 MongoDB Atlas 클러스터에서 지원됩니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하세요.

The db.getCollection() object can access any collection methods.

지정된 컬렉션은 서버에 존재할 수도 있고 존재하지 않을 수도 있습니다. 컬렉션이 존재하지 않는 경우, MongoDB는 db.collection.insertOne() 과 같은 쓰기 작업의 일부로 컬렉션을 암시적으로 생성합니다.

The following example uses db.getCollection() to access the auth collection and insert a document into it.

var authColl = db.getCollection("auth")
authColl.insertOne(
{
usrName : "John Doe",
usrDept : "Sales",
usrTitle : "Executive Account Manager",
authLevel : 4,
authDept : [ "Sales", "Customers"]
}
)

이렇게 하면 다음이 반환됩니다.

{
"acknowledged" : true,
"insertedId" : ObjectId("569525e144fe66d60b772763")
}

The previous example requires the use of db.getCollection("auth") because of a name conflict with the database method db.auth(). Calling db.auth directly to perform an insert operation would reference the db.auth() method and would error.

The following example attempts the same operation, but without using the db.getCollection() method:

db.auth.insertOne(
{
usrName : "John Doe",
usrDept : "Sales",
usrTitle : "Executive Account Manager",
authLevel : 4,
authDept : [ "Sales", "Customers"]
}
)

db.auth() 메서드에 insertOne 메서드가 없어서 작업 오류가 발생했습니다.

이 페이지 평가하기

이 페이지의 내용