Exam question 5. which database is it?

Hi! when u say to use collection ‘cities’, how to know which db this collection belongs to?
and how to connect to this db?
thanks

Hello Mariana.
I think this question is a little bit theoretical. It shows one example of a document in this collection, but it does not give you the whole collection.
One thing that helped me was to create a cities collection with that single document. With that you can test the pipelines and perform the analysis needed to answer the question.

2 Likes

Yes, you are right, to answer the question it is enough to understand theory. But during the whole course I suffered many times from seeing on video how lecturer uses some collection, but did not show which database he use for it. Is there any command how to check based on the name of collection, which db it belongs to?
and also in some cases lecturer has shown that he uses database ‘company’ with collection 'startup"(or ‘companies’ sorry don’t remember exact name) and I don’t really understand how to access this db if I wanted to practice examples given in video?
Thanx!

@ Mariana_45491

In general, remember that the database name is really mostly irrelevant to your work with a collection – the database name is in a sense just a “folder” holding collections. I usually create a new db with the name of the course, for example ‘m121’, and then load all the collections into that.

To answer your specific question, you can use the command db.collection.stats() to display the full namespace of the collection, which will consist of the database name and the collection name – for example, ‘m121.testcollection’.

This is one thing I like about MongoDB. The fact that it is schema less allows the creation of databases and collections on the fly. You can test concepts within seconds without the overhead of create tables, determining data types. For example, if you do not know if it is preferable to have 2 collections or 1. No problem, you start with everything in the same document with arrays or sub-documents. It will be very eazy to seperate the data later if you discover it is better. You just and write your data as if it was a simple. Very easy, very agile.