Posts

Showing posts with the label mongodb-query

How to match the two strings with and without including spaces

For example: In DB I've the string value like "cell phones". If I get the string value like "cellphones" from frontend. How can I compare it with DB string and get the related string values in response. Just remove those spaces from the response you are getting after query find then pass the response to require input field. Then match that string with front-end or input string. If both matches load the required content. Suppose the collection name is Category. Then the sample query will be like this Category.find().exec((err, categories) => { var details=[] var matchCategory=[] categories.map((category,key)=>{ var obj ={} obj.name = category.name.toLowerCase().replace(/\s/g, "") details.push(obj); }) if(details.length > 0){ var detailsLength=details.length details.map((category,key)=>{ if(category.name=="cellphones"){ //...