Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mongodb find like

db.users.find({"name": /.*m.*/});

db.users.find({"name": /m/});

Items.find({"description": {$regex: ".*" + variable + ".*"}}).fetch();
Comment

like mongodb

db.collection.find( { "url": { "$regex": ".*a.*"} } );
Comment

how to query mongodb with like

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.
Comment

like in mongodb

db.users.find({"name": /m/})
Comment

like in mongodb

db.users.find({"name": /.*m.*/})
Comment

like in mongodb

-- 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%"
Comment

mongodb like query

// find tables/collection in a db - case sensitive
db.getCollectionNames().filter(function (collection) { return /mobile/.test(collection) })
Comment

mongo db like

db.users.find({name: /ro$/}) //like '%ro'
Comment

like operator mangodb

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',
        })
    })
}
Comment

mongo db like

db.users.find({name: /a/})  // Like '%a%'
Comment

PREVIOUS NEXT
Code Example
Javascript :: find unique objects in an array of objects in javascript 5 
Javascript :: how to remove first element from array in javascript 
Javascript :: adding debounce in autocomplete material ui 
Javascript :: remove 0 after decimal point in javascript 
Javascript :: creatable select react 
Javascript :: stripe angular 
Javascript :: Search array of objects for existing value 
Javascript :: how to set selected value of dropdown in javascript 
Javascript :: use of map in react 
Javascript :: convert a string array into object using kerys 
Javascript :: how to get json response from rest api in node js 
Javascript :: Get the Last Items in an Array 
Javascript :: JavaScript block-scoped Variable9 
Javascript :: javascript merge two array with spread operator 
Javascript :: react datepicker 
Javascript :: convert celsius to fahrenheit javascript 
Javascript :: react scrip for deplot heroku 
Javascript :: jquery vs react 
Javascript :: jQuery DataTables Checkboxes 
Javascript :: query string to object javascript 
Javascript :: math random javascript 
Javascript :: how to import in react js 
Javascript :: alert javascript react native 
Javascript :: how to run cypress test 
Javascript :: includes not working 
Javascript :: create or update in sequelize 
Javascript :: byte to integer js 
Javascript :: how to use nodemailer 
Javascript :: javascript span style 
Javascript :: arrow function 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =