Install mongodb

2 months ago

Go to mongodb website. They have many version u just need to select the default one

https://www.mongodb.com/download-center?jmp=nav#community

This is where you need to work with

C:\Program Files\MongoDB\Server\3.4\bin

Noted the application call mongod it all you need to do

Window + R
type cmd enter

work with command line from here

go to directory
 cd C:\Program Files\MongoDB\Server\3.4\bin

// run mongodb app 
mongod

You will get error

C:\data\db not found
// to create that just type the following command from anywhere. / mean home.
mkdir /data/db

This will create folder c: data / db in your pc

In the mongodb bin directory type mongod again. This time it will work

Toke mongob available from anywhere in your command line.

Start -> right click ->computer ->property -> advance system settings -> environment variables button ->User availables for USERNAME click New -> name: PATH, variable value: C:\Program Files\MongoDB\Server\3.4\bin

Done

Now you can type mongod from anywhere

Check and play around.

Different between mongd and mongo

- Mongod = server. 

- mongo = client.

=> Before you work with mongodb you need to start the server first by type 

C:\Users\kinny
λ mongod
2017-07-03T07:53:52.473+0700 I CONTROL  [initandlisten] MongoDB starting : pid
=7124 port=27017 dbpath=C:\data\db\ 64-bit host=kinny-PC
---- more ---

at this point your mongodb server is running.

You can use mongo client to connect to it just open other command windows

C:\xampp\htdocs\mongo  (mongo@1.0.0)
λ mongo
MongoDB shell version v3.4.5
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.5
Server has startup warnings:
2017-07-03T07:53:53.256+0700 I CONTROL  [initandlisten]
2017-07-03T07:53:53.256+0700 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-07-03T07:53:53.257+0700 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-07-03T07:53:53.258+0700 I CONTROL  [initandlisten]
2017-07-03T07:53:53.259+0700 I CONTROL  [initandlisten] Hotfix KB2731284 or later update is not installed, will zero-out data files.
2017-07-03T07:53:53.259+0700 I CONTROL  [initandlisten]
>

Just ignore the warning for leaning no need to worry about it.

Type

> show dbs
admin  0.000GB
local  0.000GB
mydb   0.000GB

Thats your successful install mongodb

 

Change data location wil make your life easier later.

Change db location in mongod.conf

sudo nano /etc/mongod.conf
Change this:
dbpath=/var/lib/mongodb

With:
dbpath=/data/db

Create /data/db directory

Create the folder.

sudo mkdir -p /data/db/

Give yourself permission to the folder.

sudo chown `id -u` /data/db

Then you can run mongod without sudo. Works on OSX Yosemite

For Ubuntu

https://tecadmin.net/install-mongodb-on-ubuntu/

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
sudo echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-3.4.list
sudo apt-get update
$ sudo apt-get install mongodb-org

f you want to install any specific version of MongoDB, define the version number like below

$ sudo apt-get install mongodb-org=3.4.9 mongodb-org-server=3.4.9 mongodb-org-shell=3.4.9 mongodb-org-mongos=3.4.9 mongodb-org-tools=3.4.9

Centos 7

sudo nano /etc/yum.repos.d/mongodb-org.repo

Then, visit the Install on Red Hat section of MongoDB’s documentation and add the repository information for the latest stable release to the file:

[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc

Save and close the file.

Before we move on, we should verify that the MongoDB repository exists within the yum utility. The repolist command displays a list of enabled repositories:

kinny@centos-c-2-4gib-sgp1-01 ~]$ sudo yum repolist

repo id                         repo name                                                      status
base/7/x86_64                   CentOS-7 - Base                                                 9.591
epel/x86_64                     Extra Packages for Enterprise Linux 7 - x86_64                 12.266
extras/7/x86_64                 CentOS-7 - Extras                                                 388
updates/7/x86_64                CentOS-7 - Updates                                              1.929
repolist: 24.174

Install the MongoDB packages.

To install the latest stable version of MongoDB, issue the following command:

sudo yum install -y mongodb-org

Run test

mongod
==>data/db not found

How to fix data/db not found

// create directory
sudo mkdir -p /data/db
// give permition wrtie
sudo chown -R $USER /data/db