I need to perform a text search inside array elements. Is it possible?
Using Mongoose in Node.js and my userSchema looks like:
{
_id: "123456",
name: "Lucas"
items: [
{ title: "Shoes", description: "Very nice shoes"},
{ title: "Pants", description: "Great pants!"}
]
}
I tried to add the indexes like this:
userSchema.index({ "items.title": "text", "items.description": "text" });
But the following query returns nothing:
User.find({ $text: { $search: "Shoes" }});
mongo
shell. The text search on "Shoes" will match both thetitle
anddescription
fields, where the text values "Shoes" and "... nice shoes" are the matches. - prasad_