I have a Journal Schema which contains an array of notes. I want to implement MongoDB search in my application so that it returns the note that matches the query. Right now it returns the entire Journal Object which contains the matched note.
Journal Schema:
{
userid: {
type: String,
required: true,
},
notes: [
{
content: {
type: String,
},
},
],
}
Right now my query syntax is:
[
{
$search: {
index: 'Journal-search-index',
text: {
query: 'asdf',
path: 'content'
}
}
}
]
It returns the entire Journal object but I only want the note that matches the query. is there any way to implement that?