Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongoose search

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 :: js string to boolean 
Javascript :: javascript things to remember 
Javascript :: javascript array clear 
Javascript :: new line with javascript write 
Javascript :: toLocalString 
Javascript :: javascript remove first element from array 
Javascript :: Destructuring object from a nested object 
Javascript :: sum range javascript 
Javascript :: text background fabricjs 
Javascript :: js setattribute download 
Javascript :: javascript validate if string null undefined empty 
Javascript :: create express js project 
Javascript :: gatsby tailwind 
Javascript :: javascript string replace 
Javascript :: how to get java model attributes from javascript 
Javascript :: arrays inside array of objects 
Javascript :: uppercase first letter js 
Javascript :: splice from array javascript to remove 
Javascript :: rethrow error javascript 
Javascript :: Scaling an image to fit on canvas 
Javascript :: jquery create array 
Javascript :: react navigation hide header 
Javascript :: this in javascript 
Javascript :: Solution for Error [ERR_REQUIRE_ESM]: require() of ES Module 
Javascript :: Function is not defined - Uncaught ReferenceError 
Javascript :: accepting form data node js 
Javascript :: js loop through form inputs 
Javascript :: createelement add class 
Javascript :: js difference between two arrays of objects 
Javascript :: js remove first character from string 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =