Getting Started with MongoDB

After MongoDB is installed, you can start MongoDB client with command.

List All Databases

To see list of all available database, use

Create A Database

To create a database, run

This will create a new database if not present and switch to it.

See all Collections

Once you switched to a database using “use DB_NAME” command, you can see collections (or tables) in a database with command

Creating Tables

In MongoDB, tables are called Collections. To create a collection, use

Here i create a collection with name “servers”.

Inserting Data into a Collection

You can insert data into a collection in Jason format. To insert use following format

Example

When you insert data MongoDB will auto create a unique “_id” field.

Listing Data in Collection

To list all available data in a collection, use

This will list all data. To list specific data, you can pass JSON string to find(), for example, to find all servers to 64G RAM, use

MongoDB

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *