in Education by
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. Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
You can write it like this: db.users.find({"name": /.*m.*/}) Are you interested in learning SQL from scratch! Have a look at this interesting video on SQL provided by Intellipaat: or, like this code: db.users.find({"name": /m/}) Basically, you are looking for something that includes “m” somewhere (i.e. ‘%’ operator of SQL is equivalent to Regexp’s’.*’), not something that contains “m” anchored to the beginning of string.

Related questions

0 votes
    Input: {_id:ObjectID(123),ip:'123.123.123.123'} {_id:ObjectID(123),ip:'123.123.123.123'} ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Input: {_id:ObjectID(123),ip:'123.123.123.123'} {_id:ObjectID(123),ip:'123.123.123.123'} ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
    Input: {_id:ObjectID(123),ip:'123.123.123.123'} {_id:ObjectID(123),ip:'123.123.123.123'} ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I tried mongo replica sets for the first time. I am using ubuntu on ec2 and I booted up three instances ... replicate across machines? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I have two collection vmdetails and rsc_installtion_status , i want to select the documents from rsc_installtion_status ... Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I have a requirement to return the same length of the array provided to mongo. usernames = ['user1' ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Following query is perfectly working in mongo shell. db.collection.find({ "_id" : UUID("87aa9ed6-8485-4517 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I would like to take a list of names (e.g. john, mary, paul) and create a SQLite "select" ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have an integer field person_id with the default value of NULL. I am using a stored procedure and ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    I'm using this formula to calculate the distance between entries in my (My)SQL database which have latitude ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I have two tables containing Tasks and Notes, and want to retrieve a list of tasks with the number ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    I have multiple set of data to insert at once, say 4 rows. My table has three columns: Person, Id and ... a single SQL statement? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I have multiple set of data to insert at once, say 4 rows. My table has three columns: Person, Id and ... a single SQL statement? Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    I have the following table relationship in my database: Parent / \ Child1 Child2 \ / GrandChild I am ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I need to synchronize two tables. TableA Id Name TableB Id Name RefID --It's a Foreign key, defined as ... MATCHED BY TARGET THEN. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
...