定義
$gte$gteは、指定フィールドの値が指定した値(>=)以上のドキュメントを選択します。比較演算子はほとんどのデータ型で、 BSON 型がクエリ値の型と一致するフィールドに対してのみ比較を実行します。 MongoDB は型のブラケット処理 による限定的な BSON 間比較をサポートします。
互換性
次の環境でホストされる配置には $gte を使用できます。
MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
$gte演算子は次のような形をとります。
{ field: { $gte: value } }
例
このページの例では、sample_mflixサンプルデータセットのデータを使用します。このデータセットを自己管理型MongoDB配置にロードする方法の詳細については、サンプルデータセットをロードする を参照してください。サンプルデータベースに変更を加えた場合、このページの例を実行するには、データベースを削除して再作成する必要がある場合があります。
ドキュメントフィールドの一致
この例では、moviesコレクション内の runtime が 720 分以上のドキュメントを選択します。
db.movies.find( { "runtime": { $gte: 720 } }, { _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 dramatization of the missions and adventures of the greatest spy in British history.', runtime: 720, title: 'Reilly: Ace of Spies' }, { plot: "A 13-hour mini-series detailing James A. Michner's fictional account of the American space program from the years after World War II to the Apollo landings on the moon in the early 1970's.", runtime: 780, title: 'Space' }, { 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' }, { plot: 'Taken spans five decades and four generations, centering on three families: the Keys, Crawfords, and Clarkes. World War II veteran Russell Keys is plagued by nightmares of his abduction by ...', runtime: 877, title: 'Taken' } ]
埋め込みドキュメント フィールドに基づいてアップデートを実行
この 操作は、updateMany() という名前の埋め込みドキュメントとimdb ratingという名前のサブフィールドに一致します。 が{ highestRated: true } 以上の各ドキュメントにrating 9.5を設定します。
db.movies.updateMany( { "imdb.rating" : { $gte: 9.5 } }, { $set: { "highestRated": true } } )
{ acknowledged: true, insertedId: null, matchedCount: 2, modifiedCount: 2, upsertedCount: 0 }
imdb.rating が 9.5 より大きい最初のドキュメントのみに higestRated フィールドの値を設定するには、updateOne() を使用します。