How To Query MongoDB With “like”?

In this Tutorial, we will learn How to query MongoDB with “like” which is used for finding the match for a string or a substring that might be present in a full string which could be there.


To Query MongoDB With “like”

We use like statements to find a match in between a substring or a word with a full string. We can use it for appearing at a specific location or some time at any of the given locations.

To learn how it works and get a clear idea of it use the example given below.

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

Here we can see it used for checking the m in the name string where we can see how a substring or character (m) is used for checking in a full string (name) And it is case sensitive and to make it case insensitive we use I alphabet at the end.

For example, follow the example given below for case insensitive.

db.users.findOne({"name" : /M/i});

Here the given example is used for checking case- insensitive character

For doing the same thing in SQL we use the following Code

SELECT * FROM users  WHERE name LIKE '%m%'

here also we use % which means there can be any number of characters and if % is used before the character it means there can be n number of characters before m and it is used after character which means there can be any number of character after m in a given string.

So if there, both side of the character is % then the character we are looking for is somewhere in between in the string given but the exact place is not defined.

To learn more about it go with How To Query MongoDB With “like”?

And to learn more about java visit MongoDB Tutorials And Problems and to learn more about python follow What Is The Difference Between re. search() and re.match() Functions? In Python and keep learning and to learn any of the programing languages go though it.

Leave a Comment

%d bloggers like this: