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);
});
const oddFiltration = (arr) => {
const result = arr.filter(n => n%2);
return (result);
}
//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
# filter function
l1=[10,20,30,40,50,60,70,80]
l2= [i for i in filter(lambda x:x>30,l1)]
print(l2)
# [40, 50, 60, 70, 80]
# filter takes a function and a collection. It returns a collection of every item for which the function returned True.