如何在 mongodb 中使用 $ne
查询来查询值数组?
这是我要查询的列表
const movies = [
{
name: 'crystal',
showWatched: 'cars',
number: 1,
},
{
name: 'barbra',
showWatched: 'moonlight',
number: 2,
},
{
name: 'marry',
showWatched: 'sunshine',
number: 3,
},
{
name: 'joy',
showWatched: 'cooking',
number: 4,
},
]
下面是我尝试过的查询,我想返回所有不等于"crystal","marry"
的内容,但下面的查询却返回所有内容
const findin = ["crystal","marry"]
db.getCollection('movies').find({name: {$ne: findin} })
最佳答案
您已经很接近了,但在这种情况下,您应该使用 $nin
(不在数组中)运算符,而不是 $ne
(不等于)。就像这样:
db.getCollection('movies').find({name: {$nin: findin} })
您可以查看here.
关于arrays - 如何使用 mongodb 中的 $ne 查询来查询值数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58610775/