Answer by Kerem Atasen for How to query MongoDB with "like"
It works too:db.getCollection('collection_name').find({"field_name": /^searched_value/})
View ArticleAnswer by Sahil Patel for How to query MongoDB with "like"
If you want to use mongo JPA like query you should try this.@Query("{ 'title' : { $regex: '^?0', $options: 'i' } }")List<TestDocument> findLikeTitle(String title);
View ArticleAnswer by Sahil Thummar for How to query MongoDB with "like"
In MongoDb, can use like using MongoDb reference operator regular expression(regex).For Same Ex.MySQL - SELECT * FROM users WHERE name LIKE '%m%'MongoDb 1) db.users.find({ "name": { "$regex": "m",...
View ArticleAnswer by Binita Bharati for How to query MongoDB with "like"?
Just in case, someone is looking for a sql LIKE kind of query for a key that holds an Array of Strings instead of a String, here it is:db.users.find({"name": {$in: [/.*m.*/]}})
View ArticleAnswer by Priyanka Wagh for How to query MongoDB with "like"?
Above answers are perfectly answering the questions about core mongodb query. But when using pattern based search query such as:{"keywords":{ "$regex": "^toron.*"}}or{"keywords":{ "$regex":...
View ArticleAnswer by turivishal for How to query MongoDB with "like"?
Using javascript RegExpsplit name string by space and make array of wordsmap to iterate loop and convert string to regex of each word of namelet name = "My Name".split("").map(n => new...
View ArticleAnswer by Shubham Kakkar for How to query MongoDB with "like"?
{ $text: { $search: filter } }, ); if (indexSearch.length) { return indexSearch; } return UserModel.find( { $or: [ { firstName: { $regex: `^${filter}`, $options: 'i' } }, { lastName: { $regex:...
View ArticleAnswer by g10guang for How to query MongoDB with "like"?
Skip this answer, if you don't use go driver.filter := bson.M{"field_name": primitive.Regex{ Pattern: keyword, Options: "", },}cursor, err := GetCollection().Find(ctx, filter)Use regex in $in query,...
View ArticleAnswer by waseem khan for How to query MongoDB with "like"?
One way to find the result as with equivalent to like querydb.collection.find({name:{'$regex' : 'string', '$options' : 'i'}}) Where i use for cases insensitive fetch dataAnother way by which we can get...
View ArticleAnswer by ajay_fuel_stock_lamp_stack for How to query MongoDB with "like"?
There are various ways to accomplish this.simplest-onedb.users.find({"name": /m/}){ <field>: { $regex: /pattern/, $options: '<options>' } }{ <field>: { $regex: 'pattern', $options:...
View ArticleAnswer by Ezequias Dinella for How to query MongoDB with "like"?
You can query with a regular expression:db.users.find({"name": /m/});If the string is coming from the user, maybe you want to escape the string before using it. This will prevent literal chars from the...
View ArticleAnswer by KayV for How to query MongoDB with "like"?
Here is the command which uses starts with paradigmdb.customer.find({"customer_name" : { $regex : /^startswith/ }})
View ArticleAnswer by Lazaro Fernandes Lima Suleiman for How to query MongoDB with "like"?
If you have a string variable, you must convert it to a regex, so MongoDb will use a like statement on it. const name = req.query.title; //Johndb.users.find({ "name": new Regex(name) });Is the same...
View ArticleHow to query MongoDB with "like"?
I want to query something with SQL's like query: SELECT * FROM users WHERE name LIKE '%m%' How to do I achieve the same in MongoDB? I can't find an operator for like in the documentation.
View ArticleAnswer by Joshua Partogi for How to query MongoDB with "like"?
You would use regex for that in mongo. e.g: db.users.find({"name": /^m/})
View ArticleAnswer by Kyle H for How to query MongoDB with "like"?
That would have to be: db.users.find({"name": /.*m.*/}) or, similar: db.users.find({"name": /m/}) You're looking for something that contains "m" somewhere (SQL's '%' operator is equivalent to Regexp's...
View ArticleAnswer by leon for How to query MongoDB with "like"?
In PHP, you could use following code: $collection->find(array('name'=> array('$regex' => 'm'));
View ArticleAnswer by Afshin Mehrabani for How to query MongoDB with "like"?
In PyMongo using Python Mongoose using Node.js Jongo, using Java mgo, using Go you can do: db.users.find({'name': {'$regex': 'sometext'}})
View ArticleAnswer by brenoriba for How to query MongoDB with "like"?
You can use where statement to build any JS script: db.myCollection.find( { $where: "this.name.toLowerCase().indexOf('m') >= 0" } ); Reference: http://docs.mongodb.org/manual/reference/operator/where/
View ArticleAnswer by Eddy for How to query MongoDB with "like"?
If using node.js, it says that you can write this: db.collection.find( { field: /acme.*corp/i } ); //or db.collection.find( { field: { $regex: 'acme.*corp', $options: 'i' } } ); Also, you can write...
View Article