I have this AWS Lambda function to search a Mongodb database for queries with diactrics:
module.exports.searchWithDiacritics = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
connectToDatabase()
.then(() => {
var nameRegex = new RegExp(event.pathParameters.query);
console.log(event.pathParameters.query);
Book.find({product_name: {$regex: nameRegex, $options: 'i'}}).collation({locale: 'en', strength: 2})
.then(notes => callback(null, {
statusCode: 200,
body: JSON.stringify(notes)
}))
.catch(err => callback(null, {
statusCode: err.statusCode || 500,
headers: { 'Content-Type': 'text/plain' },
body: 'Could not fetch the notes.'
}))
});
};
Why does it work when I am using sls offline but not when I am using the deployed function? Example: http://localhost:3000/dev/products/string/v%C3%A9g%C3%A9tale returns the results but https://4u2ysdnrsi.execute-api.eu-west-1.amazonaws.com/dev/products/string/v%C3%A9g%C3%A9tale returns no results.
If the query is "flash" then there is no problem ( because it does not have diacritics ). Why are the diacritics giving me issues? I also tried with options: 'iu'