1

I have this kinds of record in mongoDB.which has brackets and other characters.API is also passing same name in parameters. But due to brackets can't search records and can't pass params without brackets. Is there anyway to search exact same records with special characters ?

   {
    "_id": {
        "$oid": "5a67295523aba20014e2fed6"
    },

    "customerName": "X-TERRA EXCAVATING AND GRADING (XTEL6K-27-B-No Tier 2)",  
}

Now my search query in node.js to find customer name is

models.customer.find({ "customerName": { $regex: '.*' + customerName + '.*', $options: 'i' } },
   function(err, data) {
  console.log(data);
 }

But it does not return any record. If I pass customer name without records it return records. What regex should be used to search any kind of names with this special characters ?

Suraj
  • 576
  • 2
  • 10
  • 37

0 Answers0