mongosh Understands JavaScript
You talk to MongoDB through mongosh, the MongoDB shell. A shell is a program where you type commands and see their results. mongosh understands JavaScript, so you can type a JavaScript expression and see its value:
print("Hi from mongosh")
2 + 2
Math.max(3, 7)
Output:
Hi from mongosh
4
7
print() shows a line of text. The other two lines have no print, but you still see their results. The shell shows the result of every expression you type. That is why the queries in this course show their results without print.
Notice the empty line after Hi from mongosh. mongosh adds one after each print(). This is normal.
You will need very little JavaScript in this course. Mostly you will write documents in curly braces { } and call methods with a dot, like Math.max(3, 7).
To work with data, you use an object called db. It points to your current database. db.movies means the movies collection in that database. Almost every command from now on starts with db. and a collection name.
In the exercise, use print() to show a greeting.