How To Create Mongo Database

Posted by in Articles, Programming

Mongo database is a specific model that consists of a collection containing documents that are stored in the form of key value. Here is step by step tutorial with images , that explains how to create mongo database.
Below is a typical structure of the mongo collection :

{
_id: 1234,
Author: { name: "Ivan Blazevic", email : "hackspc@gmail.com" },
post: "how to create mongo database …",
date: { $date: "2013-09-3 13:23UTC" },
comments: [
{
korisnik: "marko32@hotmail.com",
text: "nice post!" },
{ user: "david@gmail.com",
text: "cool!" }
],
tags: [ "tutorials", "internet" ]
}

To install mongo database follow instructions from docs.mongodb.org/manual/installation.
Run Command prompt as Administrator and navigate with comand “cd” to directory mongodb/bin . Execute from the Command Prompt mongod.exe

C:\mongodb\bin\mongod.exe

mongod baza

Connect to MongoDB using the mongo.exe shell. Open another Command Prompt and issue the following command:

C:\mongodb\bin\mongo.exe

To create database called blog with collection post. Type:

use blog

mongodb use blog

After that type :

db.post.save(
{
_id: 1234,
Author: { Name: "Ivan Blazevic", email : "blaz1988@gmail.com" },
}
)

This will create database blog with collection post , that has attributes _id,Author. You can see your created data with the command :

db.post.find()

mongo create database