Learn the Basics and Get Started with MongoDB
Technically, the documents in MongoDB are BSON documents, which are binary representations of JSON documents and support more data types such as ObjectId and Timestamps.
A document in MongoDB corresponds to a row in RDBMS. And the keys of a document then correspond to the columns of a row. Similarly, just as the rows are stored in a table in RDBMS, the documents are stored in a collection in MongoDB. And at the highest level, MongoDB also has the concept of databases that store collections rather than tables.
OK, enough talking. Now let’s get started to work with MongoDB and write some code! It’s more interesting and more efficient to learn MongoDB from examples.
Before we can create a document in MongoDB, we need to have a MongoDB server available. You can use a server hosted by MongoDB Atlas, which is recommended for production usage, or install MongoDB on your computer. However, for learning purposes, it is recommended to use Docker to start a container for MongoDB instead. In this way, you can always use the latest version of MongoDB and can have more flexible settings. Once you know how to use MongoDB, you just need to change the credentials to access your production MongoDB server.
The command to start a Docker container for MongoDB is:
$ docker network create mongo-net$ docker run --detach --network mongo-net --name mongo-server \
--env MONGO_INITDB_ROOT_USERNAME=admin \
--env MONGO_INITDB_ROOT_PASSWORD=pass \