Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
Click here >
Docs Menu
Docs Home
/ /

$gt(クエリ述語演算子)

$gt

$gt は、フィールドの値が指定した値(>)を超えるドキュメントを選択します。

比較演算子はほとんどのデータ型で、 BSON 型がクエリ値の型と一致するフィールドに対してのみ比較を実行します。 MongoDB は型のブラケット処理 による限定的な BSON 間比較をサポートします。

次の環境でホストされる配置には $gt を使用できます。

  • MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

$gt 演算子の形式は次のとおりです。

{ field: { $gt: value } }

このページの例では、sample_mflixサンプルデータセットのデータを使用します。このデータセットを自己管理型MongoDB配置にロードする方法の詳細については、サンプルデータセットをロードする を参照してください。サンプルデータベースに変更を加えた場合、このページの例を実行するには、データベースを削除して再作成する必要がある場合があります。

この例では、runtime1000 分を超える moviesコレクション内のdocumentを選択します。

db.movies.find(
{ runtime: { $gt: 1000 } },
{ _id: 0, title: 1, runtime: 1, plot: 1 }
)
[
{
plot: 'The economic and cultural growth of Colorado spanning two centuries from the mid-1700s to the late-1970s.',
runtime: 1256,
title: 'Centennial'
},
{
plot: 'A documentary on the history of the sport with major topics including Afro-American players, player/team owner relations and the resilience of the game.',
runtime: 1140,
title: 'Baseball'
}
]

この updateMany() 操作は、imdb という名前の埋め込みドキュメントと rating という名前のサブフィールドに一致します。この操作は、rating9.5 より大きい document に { highestRated: true } を設定します。

db.movies.updateMany(
{ "imdb.rating" : { $gt: 9.5 } },
{ $set: { "highestRated": true } }
)
{
acknowledged: true,
insertedId: null,
matchedCount: 1,
modifiedCount: 1,
upsertedCount: 0
}

戻る

$eq

項目一覧