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

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

cursor.min()

중요

Mongo쉬 방법

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

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

Specifies the inclusive lower bound for a specific index in order to constrain the results of find(). min() provides a way to specify lower bounds on compound key indexes.

The min() method has the following parameter:

Parameter
유형
설명

indexBounds

문서

인덱스 키의 포괄적 하한값입니다.

indexBounds 매개변수의 프로토타입 형식은 다음과 같습니다.

{ field1: <min value>, field2: <min value2>, fieldN:<min valueN> }

참고

인덱스 사용하기

max() 메서드와 함께 인덱스를 사용하려면 find() 쿼리가 _id 필드의 동등 조건인 경우를 제외하고hint()메서드를 사용하여 사용하려는 인덱스를 지정해야 합니다.

min() exists primarily to support the mongos process.

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

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

참고

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

Because min() requires an index on a field, and forces the query to use this index, you may prefer the $gte operator for the query if possible. Consider the following example:

db.products.find( { _id: { $in: [ 6, 7 ] } } ).min( { price: Decimal128("1.39") } ).hint( { price: 1 } )

이 쿼리는 _id 의 인덱스가 더 나을 수 있더라도 price 필드의 인덱스를 사용합니다.

If you use min() with max() to specify a range:

  • the index bounds specified in min() and max() must both refer to the keys of the same index.

  • the bound specified by max() must be greater than the bound specified by min().

The min() and max() methods indicate that the system should avoid normal query planning. They construct an index scan where the index bounds are explicitly specified by the values given in min() and max().

경고

두 경계 중 하나를 지정하지 않으면 쿼리 계획은 한 쪽이 제한되지 않은 인덱스 스캔이 됩니다. 이렇게 하면 연산자를 모두 포함하지 않는 쿼리 또는 두 연산자를 모두 사용하여 인덱스 스캔을 보다 엄격하게 제한하는 쿼리에 비해 성능이 저하될 수 있습니다.

Unless the find() query is an equality condition on the _id field { _id: <value> }, you must explicitly specify the index with the hint() method to run min().

아래 예시에서는 다음 문서를 포함하는 products 라는 이름의 샘플 컬렉션 을 만듭니다.

db.products.insertMany([
{ "_id" : 1, "item" : "apple", "type" : "honey crisp", "price" : Decimal128("1.99") },
{ "_id" : 2, "item" : "apple", "type" : "fuji", "price" : Decimal128("1.99") },
{ "_id" : 3, "item" : "apple", "type" : "jonagold", "price" : Decimal128("1.29") },
{ "_id" : 4, "item" : "apple", "type" : "jonathan", "price" : Decimal128("1.29") },
{ "_id" : 5, "item" : "apple", "type" : "mcintosh", "price" : Decimal128("1.29") },
{ "_id" : 6, "item" : "apple", "type" : "cortland", "price" : Decimal128("1.29") },
{ "_id" : 7, "item" : "orange", "type" : "cara cara", "price" : Decimal128("2.99") },
{ "_id" : 9, "item" : "orange", "type" : "satsuma", "price" : Decimal128("1.99") },
{ "_id" : 8, "item" : "orange", "type" : "valencia", "price" : Decimal128("0.99") },
{ "_id" : 10, "item" : "orange", "type" : "navel", "price" : Decimal128("1.39") }
])

컬렉션에 다음 인덱스를 만듭니다.

db.products.createIndexes( [
{ "item" : 1, "type" : 1 },
{ "item" : 1, "type" : -1 },
{ "price" : 1 }
] )
  • Using the ordering of the { item: 1, type: 1 } index, min() limits the query to the documents that are at or above the index key bound of item equal to apple and type equal to jonagold, as in the following:

    db.products.find().min( { item: 'apple', type: 'jonagold' } ).hint( { item: 1, type: 1 } )

    이 쿼리는 다음 문서를 반환합니다.

    { "_id" : 3, "item" : "apple", "type" : "jonagold", "price" : Decimal128("1.29") }
    { "_id" : 4, "item" : "apple", "type" : "jonathan", "price" : Decimal128("1.29") }
    { "_id" : 5, "item" : "apple", "type" : "mcintosh", "price" : Decimal128("1.29") }
    { "_id" : 7, "item" : "orange", "type" : "cara cara", "price" : Decimal128("2.99") }
    { "_id" : 10, "item" : "orange", "type" : "navel", "price" : Decimal128("1.39") }
    { "_id" : 9, "item" : "orange", "type" : "satsuma", "price" : Decimal128("1.99") }
    { "_id" : 8, "item" : "orange", "type" : "valencia", "price" : Decimal128("0.99") }
  • Using the ordering of the index { price: 1 }, min() limits the query to the documents that are at or above the index key bound of price equal to 1.39 and max() limits the query to the documents that are below the index key bound of price equal to 1.99:

    참고

    The bound specified by max() must be greater than the bound specified by min().

    db.products.find().min( { price: Decimal128("1.39") } ).max( { price: Decimal128("1.99") } ).hint( { price: 1 } )

    이 쿼리는 다음 문서를 반환합니다.

    { "_id" : 10, "item" : "orange", "type" : "navel", "price" : Decimal128("1.39") }
이 페이지 평가하기

이 페이지의 내용