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

커서.allowDiskUse() (mongosh 메서드)

cursor.allowDiskUse()

중요

Mongo쉬 방법

This page documents a mongosh method. This is not the documentation for a language-specific driver, such as Node.js.

MongoDB API 드라이버의 경우 언어별 MongoDB 드라이버 설명서를 참조하세요.

Use allowDiskUse() to either allow or prohibit writing temporary files on disk when a pipeline stage exceeds the 100 megabyte limit. Starting in MongoDB 6.0, operations that require greater than 100 megabytes of memory automatically write data to temporary files by default.

allowDiskUse() 의 형식은 다음과 같습니다.

db.collection.find(<match>).sort(<sort>).allowDiskUse()

인메모리 정렬 작업에 대한 자세한 내용은 정렬 및 인덱스 사용 을 참조하세요.

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

  • 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.

MongoDB 6.0부터는 실행에 100메가바이트 이상의 메모리가 필요한 파이프라인 단계는 기본적으로 임시 파일을 디스크에 기록합니다.

참고

MongoDB 6.0 이전에는 .allowDiskUse(false)와 .allowDiskUse(true)가 동일한 효과를 가졌습니다. MongoDB 6.0에서는 mongosh와 레거시 mongo 셸이 모두 다음과 같은 방식으로 작동합니다.

allowDiskUseByDefault가 true인 경우(기본값):

  • .allowDiskUse() 추가 효과가 없습니다.

  • .allowDiskUse(true) 추가 효과가 없습니다.

  • .allowDiskUse(false) 쿼리가 임시 파일을 디스크에 쓰는 것을 금지합니다.

allowDiskUseByDefault가 false인 경우:

  • .allowDiskUse() 디스크에 임시 파일을 쓸 수 있습니다.

  • .allowDiskUse(true) 디스크에 임시 파일을 쓸 수 있습니다.

  • .allowDiskUse(false) 추가 효과가 없습니다.

cursor.allowDiskUse() has no effect on sort operations answered using an index or non-indexed ("in-memory") sort operations which require less than 100 megabytes of memory. For more complete documentation on in-memory sorts and sort index use, see Sort and Index Use.

MongoDB가 인메모리 정렬을 수행해야 하는지 확인하려면 쿼리에 cursor.explain()을 추가하고 설명 결과를 확인합니다. 쿼리 계획에 SORT 단계가 포함된 경우 MongoDB는 100메가바이트 메모리 제한에 따라 인메모리 정렬 작업을 수행해야 합니다.

_id에 기본 인덱스만 있는 컬렉션 sensors를 가정해 보겠습니다. 이 컬렉션에는 다음과 유사한 문서가 포함되어 있습니다.

{
"sensor-name" : "TEMP-21425",
"sensor-location" : "Unit 12",
"reading" : {
"timestamp" : Timestamp(1580247215, 1),
"value" : 212,
"unit" : "Fahrenheit"
}
}

The following operation includes a cursor.sort() on the field reading.timestamp. The operation also passes false to cursor.allowDiskUse() to prohibit the query from writing temporary files to disk.

db.sensors.find({"sensor-location" : "Unit 12"}).
sort({"reading.timestamp" : 1}).
allowDiskUse(false)

reading.timestamp는 인덱스에 포함되지 않으므로 MongoDB는 요청된 정렬 순서대로 결과를 반환하기 위해 인메모리 정렬 작업을 수행해야 합니다. cursor.allowDiskUse(false)를 지정하면 MongoDB는 100MB 이상의 시스템 메모리가 필요한 경우 정렬 작업을 처리할 수 없습니다. 작업에 100MB 이상의 시스템 메모리가 필요한 경우 MongoDB는 오류를 반환합니다.

이 페이지 평가하기

이 페이지의 내용