-
Hello 👋 I would like to create a fulltext search endpoint for one of my collections. My idea for now it to follow this doc to create a standard text search with weights. Also, I am wondering if I could just expose the payload Thank you in advance for your guidance 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I am not sure whether this is the best way, but, after creating an index I've simply added an endpoint within app.get('/search', async (req, res) => {
const query = `${req.query.q}` || '';
const results = await payload.db.collections['items'].find({
$text: { $search: query },
});
res.json({ results });
}); https://payloadcms.com/docs/database/mongodb#access-to-mongoose-models |
Beta Was this translation helpful? Give feedback.
Just came back to it. So far it works for me with a named index created on server (re)start: