AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。

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

$gt

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

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

  • MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです
  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

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

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

{ field: { $gt: value } }

不等価比較演算子は型ブラケットを使用します。つまり、特定のBSON型に対する比較では、異なる型の値はフィルターされます。

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

この例では、runtime が 1000 分を超える 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 という名前のサブフィールドに一致します。この操作は、rating が 9.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}
このページを評価

ドキュメンテーション