The MongoDB Basics Databases, Collections & Documents
To understand the MongoDB basics, we need to look at how data is stored in MongoDB.
Data in MongoDB is made up of three types of factors databases, collections, and documents. The database sits at the top of the scale, collections at the coming position, and documents at the bottom.
A database provides a vessel for storing and organizing data.
Each database contains one or further collections, and each collection contains zero or further documents.
A database can contain multiple collections, but a collection can not gauge multiple databases. Likewise, a collection can contain multiple documents, but a document can not gauge multiple collections.
Studio 3T organizes and presents data rudiments grounded on the MongoDB document structure, which makes it a handy tool for understanding that structure.
In the ensuing sections, you ’ll apply what you ’ve learned from the MongoDB basics and use Studio 3T to produce a database and a collection and add documents to the collection, importing the documents from a. json train. You ’ll also query the documents, view the results in different views, and also modernize some of the values.
By the end of this section, you’ll learn how to
- Create a collection from a .json file
- Review the collection in different views
- Use Visual Query Builder to query the data
- Update the data directly within the collection
The document vs collection mongodb video
What you’ll need
- A textbook editor similar as tablet( Windows) or TextEdit( macOS)
- Access to a MongoDB Atlas cluster
- Capability to download a. json train from the Internet
In MongoDB, a database contains the collections of documents. One can produce multiple databases on the MongoDB garçon.
To see how numerous databases are present in your MongoDB garçon, write the following statement in the mongo shell
Then, we lately started MongoDB so we don’t have a database except these three dereliction databases,i.e, admin, config, and original.
Naming Restriction for Database:
Before creating a database you should first learn about the picking restrictions for database
- In MongoDB, the names of the database are case asleep, but you must always flash back that the database names can not differ only by the case of the characters.
- For windows stoner, MongoDB database names can not contain any of these following characters
- For Unix and Linux druggies, MongoDB database names can not contain any of these following characters
- MongoDB database names can not contain null characters( in windows, Unix, and Linux systems).
- MongoDB database names can not be empty and must contain lower than 64 characters.
Also read :- What is The Documentation 360 api?
In the mongo shell, you can produce a database with the help of the following command
This command actually switches you to the new database if the given name doesn’t live and if the given name exists, also it’ll switch you to the being database. Now at this stage, if you use the show command to see the database list where you’ll find that your new database isn’t present in that database list because, in MongoDB, the database is actually created when you start entering data in that database.
Then, we produce a new database named GeeksforGeeks using the use command. After creating a database when we check the database list we don’t find our database on that list because we don’t enter any data in the GeeksforGeeks database.