Hello. I’m trying to implement a search. You should be able to search for users if their username partially or fuzzily fits a search query. I’m using aggregation as it makes pagination easy. Here is my current code:
const result = await this.users.aggregate([
{
$match: { $text: { $search: query } },
},
{
$sort: { score: { $meta: "textScore" } }
},
{
$facet: {
metadata: [{ $count: "count" }],
data: [{ $skip: page * pageSize }, { $limit: pageSize }]
}
}
])
This code only allows for exact matches, which isnt great as usually when you’re searching for a user you dont know their exact username.
I can’t use atlas as this is for an open source project that makes little to no money (occasionally some from donations).
Is there any way to do this? Thanks in advance.