Filtering problems with AND operation

System Information
  • Strapi Version: 3.6.1
  • Operating System: Windows
  • Database: LiteSQL
  • Node Version: 14.15.4
  • NPM Version: 6.14.10
  • Yarn Version: 1.22.10

Hi everyone. I’ve got a recipe app that has “recipes” and “ingredients” collections. The collections have many to many relationships.

For example, Recipe #1 has rice, tomato, and carrot ingredients. Recipe #2 has rice and potato.

Now I need to receive all recipes which include both tomato AND rice.

I tried to use this:

http://localhost:1337/recipes?ingredients.name=rice&ingredients.name=tomato

It gives me back both recipes, even #2 which doesn’t include tomato.

Strapi documentation says that filtering implicitly supports the AND operation when specifying an array of expressions. So I tried to use this code:

const qs = require('qs')
const fetch = require('node-fetch')

const query = qs.stringify({
  _where: [{ 'ingredients.name': 'rice' }, { 'ingredients.name': 'tomato' }],
})


fetch(`http://localhost:1337/recipes?${query}`)
  .then((response) => {
return response.json()
  })
  .then((res) => {
console.log(res)
  })

But it doesn’t seem to work. I receive an empty array. Where am I wrong? Any ideas?