1

My Shows documents are like this

{
  _id: '',
  summary: 'The pink cat ate all the cake"
}

I am writing node js code using mongoose like this to have a text index on the summary field

exports.textIndex = async (req, res) => {
  try{

    await Shows.createIndexes({summary: "text"});
    
    const data = await Shows.aggregate([
      {
        $match: { $text: { $search: "pink cake" } }
      }
    ]);

    res.status(200).json({message: 'Success', data});

  }catch(e){res.status(500).json({message: e.message});}
};

But this gives a mongodb error as such:

{
    "message": "text index required for $text query"
}

Where am I going wrong?

Vinita
  • 1,834
  • 2
  • 8
  • 20
  • Take a look at https://stackoverflow.com/questions/24714166/full-text-search-with-weight-in-mongoose – Joe Jun 25 '21 at 05:34

0 Answers0