router.get("/Search", authenticateToken, async (req, res) => {
let search = req.query.tearms;
// Create expression
var re = new RegExp(search, "i");
let find = {};
let find2 = {};
if (search != undefined && search != "") {
//This all are the fields that will used as match
find = {
$or: [
{ firstName: { $regex: re } },
{ lastName: { $regex: re } },
{ username: { $regex: re } },
],
};
}
let dataSearched = await accounts
.find(find)
.select("firstName lastName username profileImage")
.limit(10);
res.json(dataSearched);
});
var re = new RegExp(req.params.search, 'i');
app.User.find().or([{ 'firstName': { $regex: re }}, { 'lastName': { $regex: re }}]).sort('title', 1).exec(function(err, users) {
res.json(JSON.stringify(users));
});