I have a app which will need to perform search for both string and integer type. I tried analysing and got the solution to use full text search feature for mongodb( atlas) which is working fine, but i need to do a integer search also for the same in which case this feature seems to be not a good one.Below is the code i tried
if(typeof(search_Value)!== "string"){
var getSearchResult=collection_name.find({
"$expr": {
"$regexMatch": {
"input": {"$toString": "$orderId"},
"regex": /123/
}
}
}).limit(10).skip(5) //for pagination
}
else{
var getSearchResult=collection_name.find({$text: {$search: "london"}}).limit(10).skip(5) // for pagination
}
I need a more guidance as how can I proceed the same in a single function to handle both text and integer search? I searched some plugins but they all seem to be supporting only text search .Kindly help me regarding this.