Atlas Search - search in array of objects with text operator as AND condition

Since a query array performs an OR search you need to add multiple embeddedDocument operators to the compound must array.

[
	{
		$search: {
			index: "hotels_content",
			compound: {
				must: [
					{
						embeddedDocument: {
							path: "facilities",
							operator: {
								text: {
									path: "facilities.id",
									query: "free-wifi"
								}
							}
						}
					},
					{
						embeddedDocument: {
							path: "facilities",
							operator: {
								text: {
									path: "facilities.id",
									query: "by-the-beach"
								}
							}
						}
					}
				]
			}
		}
	}
]

I’m looking for the same solution and this was the best I could come up with. If anyone has a better idea please comment!

3 Likes