Refer to the code below:
{$or: [
{titleLong: { $regex: regExp } },
{catalog: { $regex: regExp } },
{catalogNbr: { $regex: regExp } }
]}
I am trying to find the documents whose fields match a certain regex expression. For example, there's this document.
{course: {titleLong: "Introduction to analysis of algorithms"},
{catalog: "cs3333"},
{catalogNbr: "3333"}}
and when the user types "intro algo" or "3333" or "cs3333" the document should be returned. I tried /(intro|algo)/gi but it doesn't work becaue it returns all documents that either have intro or algo. Also, the g options doesn't seem to work. I also found the following regex:
(?=.*\bintro\b)(?=.*\balgo\b).+
But this only finds documents that have words that are exactly like intro and misses introduction.
(?=.*intro)(?=.*algo).+\bto find entries with words starting with the values:(?=.*\bintro)(?=.*\balgo).+