mongodb 操作符

操作符

$eq 匹配等于指定的值

col.find({price: {$eq: 1}})
// [{price: 1}]

$gt 匹配大于指定的值

col.find({price: {$gt: 2}})
// [{price: 3}, {price: 4}, {price: 5}]

$gte 匹配大于或等于指定值的值

col.find({price: {$gte: 2}})
// [{price: 2}, {price: 3}, {price: 4}, {price: 5}]

$in 匹配数组中指定的任何值

col.find({price: {$in: [2, 3]}})
// [{price: 2}, {price: 3}]

$lt 匹配小于指定值的值

col.find({price: {$lt: 2}})
// [{price: 1}]

$lte 匹配小于或等于指定值的值

col.find({price: {$lte: 2}})
// [{price: 1}, {price: 2}]

$ne 匹配所有不等于指定值的值

col.find({price: {$ne: 1}})
// [{price: 2}, {price: 3}, {price: 4}, {price: 5}]

$nin 不匹配数组指定的任何值

col.find({price: {$nin: [1, 2, 3]}})
[{price: 4}, {price: 5}]
posted @ 2020-09-16 18:20  渡心°  阅读(170)  评论(0编辑  收藏  举报