I'm using MongoDB
as my database engine and trying to execute a find
query based on a given keyword. If all of the data fields are type of String
, then I could perform the find
query like this:
test.find({
$or: [
{'field1': {'$regex': req.body.keyword} },
{'field2': {'$regex': req.body.keyword} }
]})
.then(function(records) {
if(records.length >= 1) {
return res.json({error: false, message: null, data: records});
} else {
return res.json({error: false, message: "No results", data: null});
}
});
However, I have some fields that has a field type of Number
and $reqex
cannot be used with any other types than String
.
Is it even possible to perform a find
query on different data types? Any help/ideas/thoughts are much appreciated!