db.users.find({"name": /.*m.*/});
db.users.find({"name": /m/});
Items.find({"description": {$regex: ".*" + variable + ".*"}}).fetch();
db.collection.find( { "url": { "$regex": ".*a.*"} } );
db.users.find({"name": /m/})
or
db.users.find({"name": /.*m.*/})
You're looking for something that contains "m" somewhere
(SQL's '%' operator is equivalent to Regexp's '.*'),
not something that has "m" anchored to the beginning of the string.
db.users.find({"name": /m/})
db.users.find({"name": /.*m.*/})
-- mongodb
db.people.find( { user_id: /bc/ } )
-- or
db.people.find( { user_id: { $regex: /bc/ } } )
-- sql
SELECT *
FROM people
WHERE user_id like "%bc%"
-- mongodb
db.people.find( { user_id: /^bc/ } )
-- or
db.people.find( { user_id: { $regex: /^bc/ } } )
--sql
SELECT *
FROM people
WHERE user_id like "bc%"
// find tables/collection in a db - case sensitive
db.getCollectionNames().filter(function (collection) { return /mobile/.test(collection) })
db.users.find({name: /ro$/}) //like '%ro'
let like = req.body.like;
// if request is a like
if (like) {
Card.update({
'_id': mongoose.Types.ObjectId(card_id),
'likedBy': { '$ne': mongoose.Types.ObjectId(user_id) }
}, {
'$inc': { 'likes': 1 },
'$push': { 'likedBy': mongoose.Types.ObjectId(user_id) }
}, function(err) {
if (err) {
console.log(err);
return res.json({
'state': false,
'msg': err
})
}
return res.json({
'state': true,
'msg': 'Liked',
})
})
} else if (!like) { // if request is dislike
Card.update({
'_id': mongoose.Types.ObjectId(card_id),
'likedBy': mongoose.Types.ObjectId(user_id)
}, {
'$inc': { 'likes': -1 },
'$pull': { 'likedBy': mongoose.Types.ObjectId(user_id) }
}, function(err,) {
if (err) {
console.log(err);
return res.json({
'state': false,
'msg': err
})
}
return res.json({
'state': true,
'msg': 'Disliked',
})
})
}
db.users.find({name: /a/}) // Like '%a%'