Sails js 'and' 查询

Sails js 'and' query

我有一个产品大数据集。我正在寻找名称中有 'spaghetti' 但名称中没有 'mix' 的产品,使用 sails js。我尝试了一些东西,这是一个。

Product.find({
  where: {
    name: {'contains': 'spaghetti'},
    name: {'!': 'mix'}
  }
})

这类似于 OR 查询,它会在其中找到包含意大利面条或不包含意大利面条的所有内容。当然 returns 不仅仅是意大利面。我需要的是查询 AND 而不是 OR。最好不要在已经找到的数据之上再次执行 find/where,因为我认为这会花费更长的时间。

我觉得从 OR 变成 AND 应该很容易。但是我到处找都找不到。

您可以使用两次使用相同属性的 AND 查询,如下所示:

Product.find({
  and: [
    {name: {'contains': 'spaghetti'}},
    {name: {'contains': 'mix'}}
  ]
})

然而,name: {'!': 'mix'}表示name != 'mix',即"not equal to"。不幸的是,Waterline 目前不支持 "not contains" 查询——您必须使用 query() or native() for that. See Waterline issues #1296, #666, #22 了解更多详情。