MongoDB (part 3): Install mongoDB and CRUD practice in MongoDB

Hang Nguyen
4 min readJun 16, 2022

--

  1. Download MongoDB from here.
Remember that package file should have .msi

2. Download mongoDB tools from here.

The tricky part is that you should include Tools inside bin folder of mongodb/server.

C:\Program Files\MongoDB\Server\5.0\bin should look like this

3. Edit path

Click Start -> “Edit the system environment variables”

Then click “Path” -> “Edit”

Click “New” -> Add new path to current path

Of course, restart your machine!

4. Open CMD: type in “Mongo”

Play around with some command as “show dbs”, “use <db name>”, “show collections” and so on.

5. Download dataset from here.

6. Import data into database

  • First transform bson into json readable format.

By opening cmd, direct to the folder that contains data sets. Use bsondump command as in figure below.

  • Then open MongoDBCompass and create several collections and import transformed json files. (or use cmd if you want)
Example of a collection snippet

Query practice

Please refer to this documentation for futher information.

1.Number of people named “Pauline Fournier”

2.Number of people named “Pauline Fournier” and were born before 01/01/1970

3.Number of people named:

  • Lucas Dubois
  • Camille Dubois

4.Number of all people that do not have any credit

5.Number of people that spend exactly $12.99 for cinema

6.Number of people that has the first payment is12.99 for cinema

7.Number of people that have never gone to the cinema

8. Number of women that spent more than $100 for shoes and more than $50 for pants.

9. Number of people from Warsaw, Poland that had been to cinema but not disco.

10. Number of women from Paris and men from Cracow that possess these properties:

flat

house

land

At least one of these properties has price of over $ 2,000,000 and no property is worth less than $ 500,000.

11.Number of people that have 10 payments

12. Find all people that have first name “Thomas” and return only: _id, firstName and lastName

13. Return firstName, lastName, payments (one or many) that have amount < $5.

14. Insert 1 element to payments of people in France as follows.

15. Delete market from all people records

--

--

Hang Nguyen
Hang Nguyen

Written by Hang Nguyen

Just sharing (data) knowledge

No responses yet