I would like to run a regular expression to create functionality of type "LIKE" in a virtual field in my user schema.
The following statement works for all fields except * fullName *
var searchString = stringUtils.removeMultipleSpaces(stringUtils.stripSpecialCharacters(req.param('searchString'))); var regex = new RegExp(searchString); var query = User.find().or([{ 'firstName' : { $regex: regex}}, { 'lastName': { $regex: regex }}, { 'userName': { $regex: regex }}, { 'fullName' : {$regex: regex }}]).sort('lastName'); query.select('firstName lastName userName fullName'); query.exec(function(err, users) { res.send(users); });
Declaring a virtual field in a mongoose pattern for a user
//full name UserSchema.virtual('fullName') .get(function() { return this.firstName + ' ' + this.lastName; });
What is the right approach for the regular expression fullName to work correctly?
source share