среда, 2 июля 2014 г.

How to start using the mongo db (install as windows service, create db, create user)


This post doesn't contain a piece of some special information. It's just attempt to share the most important things with beginners to start using mongo db much easier and faster. At first You need to download a mongo db distributive from official site. These are my steps for installing db:

  1. I unpacked files from archive to working folder (for example in my case it was d:\mongodb )
  2. I create a config file (mongo.config) with following content:

  3. ##store data here
    dbpath=D:\mongodb\mongodb_data
     
    ##all output go here
    logpath=D:\mongodb\mongodb_log\mongo.log
    # Enable journaling
    journal=true
    
  4. I created two folder (as You can see in config) the one was mongodb_data and the second one was mongodb_log
  5. I invoked the next script for creating windows service which will start or stop db server
    D:\mongodb\bin\mongod.exe --config "D:\mongodb\mongo.config"
         --install
         --serviceDisplayName "MongoDB"
         --serviceDescription "MongoDB Server Instance"
    
    Have a look on one interesting moment. Result of Your invoking You are able to found in mongo.log and this result might be failure. For example:
    2014-07-01T21:30:41.371+0300 Trying to install Windows service 'MongoDB'
    2014-07-01T21:30:41.371+0300 Error connecting to the Service Control Manager: Access is denied. (5)
    
    The reason of this error is very simple I just forgotten to start Far manager as Administrator :) And the success message will be:
    2014-07-01T21:32:46.175+0300 Trying to install Windows service 'MongoDB'
    2014-07-01T21:32:46.208+0300 Service 'MongoDB' (MongoDB) installed with command line 'D:\mongodb\bin\mongod.exe --config D:\mongodb\mongo.config --service'
    2014-07-01T21:32:46.208+0300 Service can be started from the command line with 'net start MongoDB'
    
  6. As result was created a service.
By default mongodb use a database with name test (more details here)
Few examples
-- create database with name mydb
use mydb

-- create user
db.createUser({user: "customuser", pwd: "custompwd", roles: [ "readWrite", "dbAdmin" ]})

-- check user details
db.getUsers()
  • OS: Windows 7; Windows 8.1
  • Mongo db: 2.6.3

Комментариев нет:

Отправить комментарий