猫鼬——如何找到物体所在的场&;name”;不包含数字

mongoose --how to find the object where its field "name" does not contain number

本文关键字:name 数字 包含 何找 猫鼬      更新时间:2023-09-26

在mongodb模型衣服中,有一个名为name的集合。

我想查找并列出所有名称中不包含2016的产品。

例如name="just jeans black jacket 2016"或"west jeans back pants"

我的代码是:

clothes.find()
       .and([{name: "black"},{name: {$ne: '2016'}}])

它不起作用。

我想使用mongoose聚合,但不知道如何使用它。

应该是:

clothes.find({ name: { $not: /2016/ } })

如果您需要带"黑色"和不带"2016"的名称,请执行:

clothes.find({ $and: [{ name: /black/i }, { name: { $not: /2016/ } }] })