对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。

$gt(查询谓词运算操作符)

$gt

$gt 选择字段值大于 (>) 指定值的文档。

可以使用 $gt 查找托管在以下环境中的部署:

  • MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务

$gt操作符采用以下形式:

{ field: { $gt: value } }

不等式比较操作符使用类型括号:对给定BSON类型的比较会使用过滤器过滤掉不同类型的值。

本页上的示例使用来自 sample_mflix 数据集的数据。有关如何将此数据集加载到您的自管理 MongoDB 部署中的详细信息,请参阅 加载示例数据集。如果您对示例数据库进行了任何修改,您可能需要删除并重新创建数据库,才能运行此页面上的示例。

此示例选择 movies集合中 runtime 大于 1000 分钟的 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}