Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongoose filter

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);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript typeof 
Javascript :: bfs javascript 
Javascript :: bootstrap 5 with next js 
Javascript :: jquery remove elemtns 
Javascript :: toFixed() javascript precision 
Javascript :: array spread operator in javascript 
Javascript :: import error in react 
Javascript :: javascript array randomizer 
Javascript :: how to print a array js 
Javascript :: propertyName nuxt auth 
Javascript :: add countdown timer to javascript quiz 
Javascript :: js date subtract minutes 
Javascript :: add an object to an array mongosse 
Javascript :: es6 in nodejs 
Javascript :: tab key event in angular 
Javascript :: JavaScript next() Method 
Javascript :: js date in arabic 
Javascript :: promise in javascript 
Javascript :: jquery placeholder 
Javascript :: for loop java script 
Javascript :: js reverse a number 
Javascript :: lodash isempty 
Javascript :: writefile in node js 
Javascript :: Using the reverse method to Reverse an Array 
Javascript :: animated typing js 
Javascript :: javascript iterate over map values 
Javascript :: js array pop 
Javascript :: get selected option text jquery 
Javascript :: create audio tag javascript 
Javascript :: date string to date in js 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =