| 写法 | $where: "this.rx > this.tx" 或函数 |
|---|---|
| 性能 | 逐文档执行 JavaScript,无索引可用 |
示例
示例
db.metrics.find({ $where: "this.rx > this.tx" })执行任意 JS 存在注入与性能风险,等效逻辑用 $expr 表达,能避免脚本执行开销。
用 JavaScript 表达式逐文档过滤(this 指向文档);无法利用索引且执行任意脚本,只适合小集合或临时排查。
| 写法 | $where: "this.rx > this.tx" 或函数 |
|---|---|
| 性能 | 逐文档执行 JavaScript,无索引可用 |
db.metrics.find({ $where: "this.rx > this.tx" })