Sample in cloud.mongodb.com
{ title : { $regex: "краснаяАкула", $options: "i" }}
code-samples.space
Search v1 (AND)
?q_title_all_words=substr1,substr2
const getRegExpByWords = (arr) => {
// NOTE: SEE also https://coderoad.ru/3041320/Regex-AND-%D0%BE%D0%BF%D0%B5%D1%80%D0%B0%D1%82%D0%BE%D1%80
// Replace regex reserved characters:
const modifiedWords = arr.join(' ').replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
// Split your string at spaces & Encapsulate your words inside regex groups:
const regexpGroups = modifiedWords.split(' ').map((w) => ['(?=.*' + w + ')'])
// Create a regex pattern:
const regexp = new RegExp('^' + regexpGroups.join('') + '.*$', 'im')
return regexp
}
const regexp = getRegExpByWords(q_title_all_words.split(','))
options.title = { $regex: regexp }
Search v0 (OR)
?q_titles=substr1,substr2
options.title = {
$regex: new RegExp(q_titles.split(',').join('|')),
$options: 'i',
}
Substr
?q_title=substr
{"header" : { "$regex": q_title, "$options": "i" }}
https://stackoverflow.com/questions/32210122/mongoose-query-for-boolean-field