I just completed M001

I just completed M001 79/79 items with 92% overall grade, {85% homework, 100% exam}. Now, I have a few questions.

  1. In the final exam, all of the answers were supposed to give using Compass. I want to know when it is better to use Compass and/or Mongo Shell?

  2. What are the differences between $elemMatch and $regex operator? I find them similar, and I’m not sure when to use which one?

  3. I’ll be grateful if someone can explain to me the “sequence of execution” of below two commands.

    db.movieDetails.find({$and: [{“tomato.meter”: {$gt: 95}},
    {“metacritic”: {$gt: 88}}]},
    {_id: 0, title: 1, “tomato.meter”: 1, “metacritic”: 1})

and

db.movieDetails.find({"awards.text"}: {$regex: /^Won.*/}},
    {_id: 0, title: 1, "awards.text": 1}).pretty()

It is time to enroll in M103, now. Many thanks for these courses. I hope they’ll contribute toward my software engineering career.

Compass and Mongo Shell are two different things. The shell is your CLI into your connected server instance (basically you can do anything through the shell), whereas Compass is an GUI for mainly querying data, managing indexes and looking at some stats.

In what context do you find them similar?

The sequence of execution is determined internally by the query planner. A query predicate will most likely run first before the projection (depending on the situation).

They both are used to match exact values.

They actually do completely different operations. So if you haven’t already, suggest you review the documentation for both:

$elemMatch:
https://docs.mongodb.com/manual/reference/operator/query/elemMatch/
https://docs.mongodb.com/manual/reference/operator/projection/elemMatch/

$regex:
https://docs.mongodb.com/manual/reference/operator/query/regex/

Let us know if you need further clarity.

1 Like

Hi @ajbozdar,

I hope you found @007_jb’s response helpful.

In the final exam, we have asked users to use Compass because this is an introductory course and some learners find it easy and intuitive to work with the GUI tool. What tool to use totally depends on your use case. On a side note, there are some operations which you cannot perform in Compass but you can do it in mongo shell.

Please go through the links shared by @007_jb and get back to us if you have still have any doubts.

On a higher level, both are having a find predicate with projection applied. So, it will be a Collection Scan followed by Projection Stage in both the cases. Only the Filter will differ for both of them based on the query predicate.

I’m so glad that you found the course content helpful. Please feel free to reach out to us if you have any other query.

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Services Engineer