Mongoose.js: Find user by username LIKE value
Mongoose.js: Find user by username LIKE value
Try this code:
var name = 'Peter'; model.findOne({name: new RegExp('^'+name+'$', "i")}, function(err, doc) { //Do your action here.. });
Try this below code to solve your issue:
var data = 'Peter'; db.User.find({'name' : new RegExp(data, 'i')}, function(err, docs){ cb(docs); });
You can do following code
db.users.find( { 'username' : { '$regex' : req.body.keyWord, '$options' : 'i' } } )
collection.findOne({
username: /peter/i
}, function (err, user) {
assert(/peter/i.test(user.username))
})
var Person = mongoose.model(‘Person’, yourSchema);
Person.findOne({ “name” : { $regex: /Ghost/, $options: ‘i’ } },
function (err, person) {
if (err) return handleError(err);
console.log(‘%s %s is a %s.’, person.name.first, person.name.last, person.occupation);
});
var name = 'vijay';
model.findOne({name: new RegExp('^'+name+'$', "i")}, function(err, doc) {
//do it here
})
if (userId == 'admin')
userId = {'$regex': '.*.*'};
User.where('status', 1).where('creator', userId);
var Person = mongoose.model(‘Person’, yourSchema);
// find each person with a name contains ‘Ghost’
Person.findOne({ “name” : { $regex: /Ghost/, $options: ‘i’ } },
function (err, person) {
if (err) return handleError(err);
console.log(‘%s %s is a %s.’, person.name.first, person.name.last, person.occupation);
});
router.route('/product/name/:name')
.get(function(req, res) {
var regex = new RegExp(req.params.name, "i")
, query = { description: regex };
Product.find(query, function(err, products) {
if (err) {
res.json(err);
}
res.json(products);
});
});
var name = 'venkat';
model.findOne({name: new RegExp('^'+name+'$', "i")}, function(err, doc) {
//Do your action here..
});