New Year Sale 2026! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

MongoDB C100DBA Exam - Topic 6 Question 122 Discussion

Actual exam question for MongoDB's C100DBA exam
Question #: 122
Topic #: 6
[All C100DBA Questions]

What is the equivalent command in MongoDB for the following SQL query?

SELECT * FROM posts WHERE author like "%john%"

Show Suggested Answer Hide Answer
Suggested Answer: A

Contribute your Thoughts:

0/2000 characters
An
3 days ago
A) db.posts.find( { author: /John/ } ) is the way to go. Searching for a substring in the author field is easy peasy in MongoDB.
upvoted 0 times
...
Louisa
8 days ago
Option A is the winner! Gotta love that regex magic in MongoDB.
upvoted 0 times
...
Lucina
14 days ago
I agree, option A is the way to go. Searching for the author's name using a regular expression is the way to do it in MongoDB.
upvoted 0 times
...
Minna
19 days ago
A) db.posts.find( { author: /John/ } ) is the correct equivalent command in MongoDB for the given SQL query.
upvoted 0 times
...
Malcom
24 days ago
I'm leaning towards A too, but I wonder if there's a chance that B could be correct since it has a different format.
upvoted 0 times
...
Nana
29 days ago
I feel like I've seen something like this before, but I can't recall if MongoDB uses $like or not.
upvoted 0 times
...
Dulce
1 month ago
I remember practicing a similar question, and I think it was about using regex to match patterns. A seems to fit that.
upvoted 0 times
...
Louvenia
1 month ago
I think the answer might be A, but I'm not completely sure about the syntax for regex in MongoDB.
upvoted 0 times
...
Chau
1 month ago
I'm not too familiar with MongoDB, but based on my understanding of the SQL query, I think option A looks like the right translation. The regex /John/ should match any authors that have "john" anywhere in their name.
upvoted 0 times
...
Renato
2 months ago
Okay, let me think this through. The SQL query is using the LIKE operator to do a partial string match, so the MongoDB equivalent would be to use a regular expression. I'm leaning towards option A as the best fit.
upvoted 0 times
...
Lajuana
2 months ago
I'm a bit confused by the different options here. The SQL query is looking for a partial match on the author field, so I'm not sure if the /John/ regex is the right approach. Maybe option D with the $like operator would be better?
upvoted 0 times
...
Gregoria
2 months ago
Hmm, this looks like a straightforward SQL to MongoDB translation. I think I'll go with option A, it seems to match the SQL query the closest.
upvoted 0 times
...

Save Cancel