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 :: modal multiple images 
Javascript :: how to calculate first monday of the month in js 
Javascript :: big.js 
Javascript :: Group item by date 
Javascript :: chai js 
Javascript :: javascript link detector 
Javascript :: js create nested object from array 
Javascript :: How to add js file to a site through url 
Javascript :: chart js 
Javascript :: map values in range js 
Javascript :: Why my array resets itself when I leave my function 
Javascript :: what is prototype in javascript 
Javascript :: array indexof 
Javascript :: Updating a nested object in a document using mongoose 
Javascript :: react navbar responsive 
Javascript :: npm font awesome angular 12 
Javascript :: datepicker range npm reactjs 
Javascript :: word table to json 
Javascript :: template strings in js 
Javascript :: react onclick remove component 
Javascript :: javascript in python 
Javascript :: call function 
Javascript :: javascript array remove last 
Javascript :: Angular passing function as component input 
Javascript :: javascript reducer 
Javascript :: js then vs await 
Javascript :: how to delete object in array 
Javascript :: comments in jsx 
Javascript :: search in array javascript 
Javascript :: remix js 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =