Docs Menu
Docs Home
/
データベース マニュアル
/ / /

$strcasecmp(集計)

$strcasecmp

2 つの文字列の大文字と小文字を区別しない比較を実行します。 戻り値

  • 1 : 最初のstringが 2 番目のstringより「大きい」場合は 1 。

  • 2 つの文字列が等しい場合は 0。

  • 最初のstringが 2 番目のstringより「小さい」場合は -1。

$strcasecmp の構文は次のとおりです。

{ $strcasecmp: [ <expression1>, <expression2> ] }

引数は、文字列に変換される限り、どのような有効なでも使用できます。式の詳細については、「式演算子」を参照してください。

$strcasecmp は ASCII 文字の文字列に対してのみ、明確に定義された動作を行います。

大文字と小文字の比較については、 $cmpを参照してください。

以下のドキュメントを持つinventoryコレクションを考えてみましょう。

db.inventory.insertMany( [
{ _id: 1, item: "ABC1", quarter: "13Q1", description: "product 1" },
{ _id: 2, item: "ABC2", quarter: "13Q4", description: "product 2" },
{ _id: 3, item: "XYZ1", quarter: "14Q2", description: null }
] )

次の操作では、 $strcasecmp演算子を使用して、 "13q4" quarterフィールド値と string の 大文字と小文字を区別しない 比較を実行します。

db.inventory.aggregate(
[
{
$project:
{
item: 1,
comparisonResult: { $strcasecmp: [ "$quarter", "13q4" ] }
}
}
]
)

この操作は次の結果を返します。

{ _id: 1, item: "ABC1", comparisonResult: -1 }
{ _id: 2, item: "ABC2", comparisonResult: 0 }
{ _id: 3, item: "XYZ1", comparisonResult: 1 }

戻る

$stdDevSamp

項目一覧