Making a case-insensitive "like" query using the mongodb driver in Node
<p>I'm looking to make a query like mentioned in the title with an array of data.</p>

<p>I have this line working..</p>

<pre><code>collection.find({"name": {"$in":[/papa JOhn's/i,"Taco Bell"]}}).toArray(function(err, items) {
</code></pre>

<p>However, the data is going to be dynamic and fed into the query as an array</p>

<pre><code>restaurant_data = [rest1, rest2 .... restn]
</code></pre>

<p>I want to essentially have something like </p>

<pre><code>collection.find({"name": {"$in": /restaurant_data/i }}).toArray(function(err, items) {
</code></pre>

<h2>My Attempt..</h2>

<pre><code>let test_data = ['papa john', 'taco bell']
//Get an array of the restaurant names here

collection.find({"name": {"$in": test_data.map(element =&gt; {

  /element/i

})}}).toArray(function(err, items) {
</code></pre>

<h2>My working attempt!</h2>

<p>I got it doing this... Not sure if it's the most efficient</p>

<pre><code>let test_data = ['papa john', 'taco bell']

collection.find({"name": {"$in": test_data.map((element) =&gt; {
  var regex = new RegExp(".*" + element + ".*");
  return regex
})}}).toArray(function(err, items) {
</code></pre>