What worked for me was :
async function getByName(name) {
try {
const query = { username: { '$regex': `^${name}$`, '$options': 'i' }}
const user = await collection.findOne(query);
return user;
} catch (err) {
throw err;
}
}
You may replace the "findOne()" with a regular "find.
Write your thoughts.