Consider this collection:
{
{ name: 'first', toys: ['doll', 'car', 'doll'],
{ name: 'second', toys: ['doll', 'car'],
{ name: 'third', toys: ['doll', 'car', 'bricks'],
{ name: 'fourth', toys: ['doll', 'bricks'],
{ name: 'fifth', toys: []
}
I want to query for documents whose toys field is an array that only contains doll and car. In this case, both first and second should match. first matches because doll and car can be repeated in the array, third doesn't match because no other value must be present in the array, and fourth and fifth don't match because they don't contain both doll and car.
Using $all and $in doesn't work for me because they match third. How can I achieve this? Thanks!