2013年1月18日 星期五

Installation of MongoDB


Introduction

MongoDB (from "humongous") is a scalable, high-performance, open source, document-oriented database. Written in C++.

Installation

  1. download it in here (depend on your platform)
  2. unzip it into a folder. example : c:\mongodb\
  3. create the database file path. example : c:\mongodb\data\
  4. execute the mongodb. c:\mongodb\bin\mongod --dbpath=c:\mongodb\data\
  5. the mongodb will open at port 27017(data connection) and 28017(control panel)
  6. open the browser and enter the URL( http://localhost:28017 , and see the result as follow :

Extension - Master and Slave Structure

Concept(working)
we setting the Master/Slave structure in local computer.
  1. create the database file paths : c:\mongod\master_data\, c:\mongod\slave_data1\, c:\mongod\slave_data2\
  2. start the master : c:\mongodb\bin\mongod --master --dbpath=c:\mongod\master_data\ --port 10000
  3. start the slave1 : c:\mongodb\bin\mongod --slave --source localhost:10000 --dbpath=c:\mongod\slave_data1\ --port 20000
  4. start the slave2 : c:\mongodb\bin\mongod --slave --source localhost:10000 --dbpath=c:\mongod\slave_data2\ --port 30000
  5. done

MongoDB on Grails

Installation
  1. grails create-app mongodbTest
  2. grails install-plugin mongodb-morphia
  3. add data source
    grails-app/conf/DataSource.groovy
    mongodb {
      host = 'localhost'
      port = 27017
      databaseName = 'test'
      username = "YOUR_USERNAME"
      password = "YOUR_PASSWORD"
    }
    }
  4. grails create-mongodb-class Car
  5. add some attributes for db-class
    grails-app/mongo/Car.groovy
    class Car{
        String brand
        String title
    }
  6. grails generate-all Car
  7. grails run-app (make sure the mongodb is open)
  8. add some data by browser
  9. done

Future Work

Sharding structure(working)

Reference

沒有留言:

張貼留言