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?