| 存在性 | {err: {$exists: true}} |
|---|---|
| 类型 | {value: {$type: "string"}} |
| 多类型 | $type: ["int", "double"] |
示例
示例
db.logs.find({ err: { $exists: true } })
db.metrics.find({ value: { $type: ["int", "double"] } })$type 与 $exists 多数情况下无法有效利用索引,大集合上开销明显。
$exists 判断字段是否出现;$type 按 BSON 类型过滤,别名 number 覆盖 int/long/double/decimal,也可传类型数组。
| 存在性 | {err: {$exists: true}} |
|---|---|
| 类型 | {value: {$type: "string"}} |
| 多类型 | $type: ["int", "double"] |
db.logs.find({ err: { $exists: true } })
db.metrics.find({ value: { $type: ["int", "double"] } })