Quantcast
Channel: How to query MongoDB with "like" - Stack Overflow
Browsing all 48 articles
Browse latest View live

Answer by Deepak parmar for How to query MongoDB with "like"?

String deepakparmar, dipak, parmar db.getCollection('yourdb').find({"name":/^dee/}) ans deepakparmar db.getCollection('yourdb').find({"name":/d/}) ans deepakparmar, dipak...

View Article



Answer by saim2025 for How to query MongoDB with "like"?

You can also use the wildcard filter as follows: {"query": { "wildcard": {"lookup_field":"search_string*"}}} be sure to use *.

View Article

Answer by besthost for How to query MongoDB with "like"?

Using template literals with variables also works: {"firstname": {$regex : `^${req.body.firstname}.*` , $options: 'si' }}

View Article

Answer by Rust for How to query MongoDB with "like"?

Regex are expensive are process. Another way is to create an index of text and then search it using $search. Create a text Index of fields you want to make searchable: db.collection.createIndex({name:...

View Article

Answer by kz_sergey for How to query MongoDB with "like"?

Use aggregation substring search (with index!!!): db.collection.aggregate([{ $project : { fieldExists : { $indexOfBytes : ['$field', 'string'] } } }, { $match : { fieldExists : { $gt : -1 } } }, {...

View Article


Answer by arnav for How to query MongoDB with "like"?

>> db.car.distinct('name') [ "honda", "tat", "tata", "tata3" ] >> db.car.find({"name":/. *ta.* /})

View Article

Answer by priya raj for How to query MongoDB with "like"?

db.customer.find({"customerid": {"$regex": "CU_00000*", "$options": "i"}}).pretty() When we are searching for string patterns, always it is better to use the above pattern as when we are not sure about...

View Article

Answer by Shubham Verma for How to query MongoDB with "like"?

FullName like 'last' with status==’Pending’ between two dates: db.orders.find({ createdAt:{$gt:ISODate("2017-04-25T10:08:16.111Z"), $lt:ISODate("2017-05-05T10:08:16.111Z")}, status:"Pending",...

View Article


Answer by user3645907 for How to query MongoDB with "like"?

You have 2 choices: db.users.find({"name": /string/}) or db.users.find({"name": {"$regex": "string", "$options": "i"}}) On second one you have more options, like "i" in options to find using case...

View Article


Answer by damd for How to query MongoDB with "like"?

With MongoDB Compass, you need to use the strict mode syntax, as such: { "text": { "$regex": "^Foo.*", "$options": "i" } } (In MongoDB Compass, it's important that you use " instead of ')

View Article

Answer by CEDA for How to query MongoDB with "like"?

If you're using PHP, you can use MongoDB_DataObject wrapper like below: $model = new MongoDB_DataObject(); $model->query("select * from users where name like '%m%'"); while($model->fetch()) {...

View Article

Answer by Albert s for How to query MongoDB with "like"?

MongoRegex has been deprecated. Use MongoDB\BSON\Regex $regex = new MongoDB\BSON\Regex ( '^m'); $cursor = $collection->find(array('users' => $regex)); //iterate through the cursor

View Article

Answer by Bruno Bronosky for How to query MongoDB with "like"?

It seems that there are reasons for using both the javascript /regex_pattern/ pattern as well as the mongo {'$regex': 'regex_pattern'} pattern. See: MongoBD RegEx Syntax Restrictions This is not a...

View Article


Answer by Lakmal Vithanage for How to query MongoDB with "like"?

I found a free tool to translate MYSQL queries to MongoDB. http://www.querymongo.com/ I checked with several queries. as i see almost all them are correct. According to that, The answer is...

View Article

Answer by jarry jafery for How to query MongoDB with "like"?

If you want 'Like' search in mongo then you should go with $regex by using this query will be db.product.find({name:{$regex:/m/i}}) for more you can read the documentation as well....

View Article


Answer by Somnath Muluk for How to query MongoDB with "like"?

There are already many answers. I am giving different types of requirements and solutions for string search with regex. You can do with regex which contain word i.e like. Also you can use $options...

View Article

Answer by sravanthi for How to query MongoDB with "like"?

As Mongo shell support regex, that's completely possible. db.users.findOne({"name" : /.*sometext.*/}); If we want the query to be case-insensitive, we can use "i" option, like shown below:...

View Article


Answer by Shalabh Raizada for How to query MongoDB with "like"?

Use regular expressions matching as below. The 'i' shows case insensitivity. var collections = mongoDatabase.GetCollection("Abcd"); var queryA = Query.And( Query.Matches("strName", new...

View Article

Answer by Aqib Mumtaz for How to query MongoDB with "like"?

For Mongoose in Node.js db.users.find({'name': {'$regex': '.*sometext.*'}})

View Article

Answer by Shaishab Roy for How to query MongoDB with "like"?

In nodejs project and use mongoose use Like query var User = mongoose.model('User'); var searchQuery={}; searchQuery.email = req.query.email; searchQuery.name = {$regex: req.query.name, $options: 'i'};...

View Article
Browsing all 48 articles
Browse latest View live




Latest Images