Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoose text index on nested schema field

I have the following schema:

const Schema = ({
  metadata: {
    title: String,
    ...
  },
  ...

});

and I'm looking to create a a text index on metadata.title. I can create a text index successfully on any first level property, but I'm running into trouble with the nested title.

I've tried the following code, to no avail. Is my syntax wrong? I've had no luck with docs...

Schema.index({ 'metadata.title': 'text' });

Searching:

Schema
  .find(
    { $text : { $search : req.params.query } },
    { score : { $meta: "textScore" } })
like image 341
sir_thursday Avatar asked Aug 07 '16 00:08

sir_thursday


1 Answers

It turns out what I had originally was correct, as pointed out by @JohnnyHK. I must have had some other error that caused the index to not work...

like image 58
sir_thursday Avatar answered Sep 25 '22 05:09

sir_thursday