Hello!
I have the following documents in my MongoDB collection:
[
{
"hotelName": "Hotel ABC",
"facilities": [
{ "id": "free-wifi", "title": "Free Wi-Fi" },
{ "id": "by-the-beach", "title": "By the beach" },
{ "id": "facilities-for-disabled", "title": "Facilities for disabled" }
]
},
{
"hotelName": "Hotel DEF",
"facilities": [
{ "id": "for-elders", "title": "For elders" },
{ "id": "by-the-beach", "title": "By the beach" },
{ "id": "facilities-for-disabled", "title": "Facilities for disabled" }
]
},
{
"hotelName": "Hotel GHI",
"facilities": [
{ "id": "free-wifi", "title": "Free Wi-Fi" },
{ "id": "spa-zone", "title": "SPA Zone" },
{ "id": "facilities-for-disabled", "title": "Facilities for disabled" }
]
}
]
Now I want to search hotels with both “Free Wi-Fi” and “By the beach” facilities included, so I’m doing the following query:
[
{
$search: {
index: "hotels_content",
embeddedDocument: {
path: "facilities",
operator: {
compound: {
must: [
{
text: {
path: "facilities.id",
query: [
"free-wifi",
"by-the-beach",
],
},
},
],
},
},
},
},
},
]
But this query is not working as I expected, looks like it’s using OR expression in text
operator, so all 3 documents are returned. How can I change this query to use AND expression in the text
filter so only the first document will be returned?