Mc3 Snooty Fashions Commands to Create Database

Introduction

MongoDB is a NoSQL database solution that focuses on availability and scalability. The data is structured and stored in collections of JSON documents.

By not using a fixed information construction, MongoDB provides a comprehensive solution for loftier-volume storage in a modern distributed arrangement.

This tutorial shows yous how to use the MongoDB customer to create a new database.

how to create database in mongodb in ubuntu

Prerequisites

  • Access to terminal window/command line
  • Elevated user privileges (sudo, root, or administrator)
  • A working MongoDB installation (Centos 8 or Ubuntu)
  • A Linux or Windows organisation

Create MongoDB Database with the apply Control

MongoDB commands are issued within the MongoDB client shell.

1. To access the MongoDB vanquish, open a terminal window, and run the following command:

                mongo              

You are now in the MongoDB shell and tin can beginning issuing database commands.

2. Commencement by issuing a use command. The use command is typically used to switch to a specific database. However, MongoDB creates a new database if 1 does not exist.

                utilise example_db              

iii. The system immediately responds and switches to your new database.

example of the Use command creating a new database in mongodb

You are currently using your newly created database named example_db.

Notation: If you can't admission the MongoDB beat out, bank check whether the MongoDB service is active with sudo systemctl status mongodb . The output should confirm that the service is active (running). For farther details encounter Managing MongoDB Service.

How to List Databases in MongoDB

1. Verify the name of the electric current database by using the db  command:

                db              

Your organization should display example_db (or the proper noun you lot specified).

example of using the db command checking database name

2. List all the databases on your system with the evidence dbs  control:

                show dbs              

You may notice that your new database is not listed.

show dbs command Listing of MongoDB databases

The newly created database is empty – y'all'll need to insert data for it to display in this list.

Add MongoDB Collection with insert() Command

A collection in MongoDB is much like a table in other database applications.

The following command creates a record and inserts it into a newly created collection. A tape is a certificate with field names and values. Equally with a new database, if this record does not be, MongoDB creates information technology:

                db.Sample.insert({"SampleValue1" : 255, "SampleValue2" : "randomStringOfText"})              

Let's accept a closer look at the syntax of the control to empathize how the record and drove are created.

  • db.Sample.insert  – This is the insert control. In this case, the name Sample represents the name of the document you're inserting data into. If the document does not already exist, MongoDB automatically creates it.
  • ({  }) – The set of brackets encloses the data you are entering. Note that there'due south a set of close-brackets at the end.
  • "SampleValue1" : 255, "SampleValue2" :  "randomStringOfText" – Represents the format of the data we are entering into the record.

After you lot execute the control, you lot run across the following response:

                WriteResult({ "nInserted" : i})              

This response confirms that the organisation automatically created a drove and the record was inserted into said collection.

MongoDB confirms that you have successfully inserted data to a new collection

If you list the existing databases with the show dbs control, you'll observe that the example_db database is at present on the list.

New example_db database is visible on database list.

Query MongoDB with find Command

You tin can verify that MongoDB saved the data from the insert control using the detect control:

                db.Sample.discover()              

As a outcome, the system displays the data located within the Sample collection.

find command prints information within the collection

Conclusion

Utilise the commands in this commodity to create, display, and insert data into your MongoDB database.

MongoDB offers countless ways to construction your information and many commands to help you along the way.

Was this commodity helpful?

Yes No

Vladimir Kaplarevic

Vladimir is a resident Tech Writer at phoenixNAP. He has more than 7 years of experience in implementing eastward-commerce and online payment solutions with various global IT services providers. His articles aim to instill a passion for innovative technologies in others by providing practical advice and using an engaging writing style.

0 Response to "Mc3 Snooty Fashions Commands to Create Database"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel