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

$mul (업데이트 연산자)

$mul

Multiply the value of a field by a number. To specify a $mul expression, use the following prototype:

{ $mul: { <field1>: <number1>, ... } }

업데이트할 필드에는 숫자 값이 포함되어야 합니다.

내장된 문서나 배열에 <field> 기호를 지정하려면 점 표기법을사용하십시오.

Starting in MongoDB 5.0, mongod no longer raises an error when you use an update operator like $mul with an empty operand expression ( { } ). An empty update results in no changes and no oplog entry is created (meaning that the operation is a no-op).

MongoDB 5.0부터 업데이트 연산자는 문자열 기반 이름이 있는 문서 필드를 사전순으로 처리합니다. 숫자 이름이 있는 필드는 숫자 순서대로 처리됩니다. 자세한 내용은 업데이트 운영자 동작을 참조하십시오.

If the field does not exist in a document, $mul creates the field and sets the value to zero of the same numeric type as the multiplier.

$mul 는 단일 문서 내에서 원자적으로 수행되는 연산입니다.

혼합된 숫자 유형(32비트 정수, 64비트 정수, Double, Decimal128)의 값과의 곱셈은 숫자 유형의 변환을 초래할 수 있습니다. 혼합 숫자 형식의 값을 곱하는 경우 다음 형식 변환 규칙이 적용됩니다.

데이터 유형
32비트 정수
64비트 정수
Double
Decimal128

32비트 정수

32비트 또는 64비트 정수

64비트 정수

Double

Decimal128

64비트 정수

64비트 정수

64비트 정수

Double

Decimal128

Double

Double

Double

Double

Decimal128

Decimal128

Decimal128

Decimal128

Decimal128

Decimal128

참고

  • 두 개의 32비트 정수의 곱이 32비트 정수의 최대값을 초과하는 경우 결과는 64비트 정수입니다.

  • 64비트 정수의 최대값을 초과하는 모든 유형의 정수 연산에서는 오류가 발생합니다.

products 컬렉션을 생성합니다.

db.products.insertOne(
{ "_id" : 1, "item" : "Hats", "price" : Decimal128("10.99"), "quantity" : 25 }
)

In the following operation, db.collection.updateOne() updates the document. The $mul operator multiplies the price field by 1.25 and the quantity field by 2:

db.products.updateOne(
{ _id: 1 },
{ $mul:
{
price: Decimal128( "1.25" ),
quantity: 2
}
}
)

업데이트된 문서에서:

  • price 는 원래 값인 10.99에 1.25를 곱한 값입니다.

  • quantity 는 원래 값인 25에 2를 곱한 값입니다.

{ _id: 1, item: 'Hats', price: Decimal128("13.7375"), quantity: 50 }

다음 문서를 products 컬렉션에 추가합니다:

db.products.insertOne( { _id: 2, item: "Unknown" } )

In the following operation, db.collection.updateOne() attempts to apply the $mul operator to a field that is not in the document:

db.products.updateOne(
{ _id: 2 },
{ $mul: { price: Decimal128("100") } }
)

db.collection.updateOne() 작업

  • price 필드를 삽입합니다.

  • Decimal128("0")을 설정합니다.

{ "_id" : 2, "item" : "Unknown", "price" : Long(0) }

필드는 price 는 승수와 동일한 유형인 Decimal128입니다.

다음 문서를 products 컬렉션에 추가합니다:

db.products.insertOne( { _id: 3, item: "Scarf", price: Decimal128("10") } )

In the following operation, db.collection.updateOne() uses the $mul operator to multiply the value in the price field Decimal128(10) by Int32(5):

db.products.updateOne(
{ _id: 3 },
{ $mul: { price: Int32(5) } }
)

이 연산을 수행하면 다음 문서가 생성됩니다.

{ _id: 3, item: 'Scarf', price: Decimal128("50") }

The value in the price field is of type Decimal128. See Multiplication Type Conversion Rules for details.

이 페이지 평가하기

이 페이지의 내용