Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Submitted
Created by Guest
Created on Jan 24, 2024

EmbeddedDocuments Search multiple compound fields

Today, it doesn't seem that a $search index on a list of object documents allows for an embeddedDocument search to match on multiple properties within the document. So, if I have: [{ name: 'Doc 1', attached: [ { name: 'a', type: 'string' }, { name: 'b', type: 'number' }] }, { name: 'Doc 1', attached: [ { name: 'a', type: 'string' }, { name: 'b', type: 'string' }] }] I would like to be able to write a compound query like this: [ { $search: { index: "default", compound: { must: [ { embeddedDocument: { path: "attached", operator: { compound: { must: [ { text: { path: "attached.name", query: "b", }, }, { autocomplete: { path: "attached.type", query: "string", }, }, ], }, }, }, }, ], }, }, }] And for it to only find and return this: { name: 'Doc 1', attached: [ { name: 'a', type: 'string' }, { name: 'b', type: 'string' }] }