1. Mongodb  시작과 종료

 

[Windows]

C:\> mkdir c:\mdb

C:\> mongod --dbpath c:\mdb\

 

 Fri Dec 30 13:34:11 [initandlisten] MongoDB starting : pid=3592 port=27017 dbpath=c:\mdb\ 64-bit

  host=PLAN

 Fri Dec 30 13:34:11 [initandlisten] db version v2.0.2, pdfile version 4.5

 Fri Dec 30 13:34:11 [initandlisten] git version: 514b122d308928517f5841888ceaa4246a7f18e3

 Fri Dec 30 13:34:11 [initandlisten] build info: windows (6, 1, 7601, 2, 'Service Pack 1') BOOST_LIB

 _VERSION=1_42

 Fri Dec 30 13:34:11 [initandlisten] options: { dbpath: "c:\mdb\" }

 Fri Dec 30 13:34:11 [initandlisten] journal dir=c:/mdb/journal

 Fri Dec 30 13:34:11 [initandlisten] recover : no journal files present, no recovery needed

 Fri Dec 30 13:34:11 [initandlisten] preallocateIsFaster=true 9.36

 Fri Dec 30 13:34:12 [initandlisten] preallocateIsFaster=true 19.96

 Fri Dec 30 13:34:14 [initandlisten] preallocateIsFaster=true 9.04

 Fri Dec 30 13:34:14 [initandlisten] preallocateIsFaster check took 3.447 secs

 Fri Dec 30 13:34:14 [initandlisten] preallocating a journal file c:/mdb/journal/prealloc.0

                20971520/1073741824     1%

                41943040/1073741824     3%

                 ……………………….


[Linux]

 [mongodb@localhost ~]$ mongod --dbpath /home/mongodb/mongodb/ &

[1] 2843

[mongodb@localhost ~]$ Sun Feb 19 23:13:44 [initandlisten] MongoDB starting : pid=2843 port=27017 dbpath=/home/mongodb/mongodb/ 64-bit host=localhost.localdomain

Sun Feb 19 23:13:44 [initandlisten] db version v2.0.3-rc1, pdfile version 4.5

Sun Feb 19 23:13:44 [initandlisten] git version: ac5eb821bb87bc22fe1b4c9ea763dceec0df9d9a

Sun Feb 19 23:13:44 [initandlisten] build info: Linux ip-10-110-9-236 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41

Sun Feb 19 23:13:44 [initandlisten] options: { dbpath: "/home/mongodb/mongodb/" }

Sun Feb 19 23:13:44 [initandlisten] journal dir=/home/mongodb/mongodb/journal

Sun Feb 19 23:13:44 [initandlisten] recover : no journal files present, no recovery needed

Sun Feb 19 23:13:44 [initandlisten] preallocateIsFaster=true 2.1

Sun Feb 19 23:13:44 [websvr] admin web console waiting for connections on port 28017

Sun Feb 19 23:13:44 [initandlisten] waiting for connections on port 27017

 

 

2. MongoDB의 접속과 용어 이해

 

* MySQL & Oracle & Mongo DB의 용어 이해

 

MySQL executable

Oracle executable

Mongo executable

mysqld

oracle

mongod

mysql

sqlplus

mongo

RDBMS terminology

Mongo terminology

database

database

table

collection

index

index

row

BSON document

column

BSON field

join

embedding and linking

primary key

_id field

 

 

C:\mongodb\bin> mongo

MongoDB shell version: 2.0.2

connecting to: test

>

 

> help

        db.help()         help on db methods

        db.mycoll.help()  help on collection methods

        rs.help()         help on replica set methods

        help admin        administrative help

        help connect      connecting to a db help

        help keys         key shortcuts

        help misc         misc things to know

        help mr           mapreduce

 

    show dbs          show database names

        show collections  show collections in current database

        show users        show users in current database

        show profile      show most recent system.profile entries with time >= 1ms

        show logs         show the accessible logger names

        show log [name]   print out the last segment of log in memory, 'global' is default

        use <db_name>     set current database

        db.foo.find()              list objects in collection foo

        db.foo.find( { a : 1 } )   list objects in foo where a == 1

        it                         result of the last line evaluated;

        DBQuery.shellBatchSize = x set default number of items to display on shell

        exit                       quit the mongo shell

>

 

> use mdb

switched to db mdb

>

 

> use admin

switched to db admin

>

 

> db.shutdownServer()             <-- MongDB 종료 명령어

Sun Jan 22 17:39:31 DBClientCursor::init call() failed

Sun Jan 22 17:39:31 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1

server should be down...

Sun Jan 22 17:39:31 trying reconnect to 127.0.0.1

Sun Jan 22 17:39:32 reconnect 127.0.0.1 failed couldn't connect to server 127.0.0.1

Sun Jan 22 17:39:32 Error: error doing query: unknown shell/collection.js:151

 

 

** MongoDB의 종료는 Process를 Ctrl-C 또는 Kill 명령어로 강제 종료하는 방법도 있지만 이러한 비정상적인

 

   종료 방법은 권장하지 않습니다. 다른 일반적인 DBMS, 애플리케이션들 처럼 예기치 못하는 장애 현상이 발생할

 

  수도 있기 때문입니다. 데이터베이스는 안전한 관리가 무엇보다 요구됩니다. (리눅스에서의 작업도 동일)

 

** 다름은 Php와 같은 드라이버 내에서 종료하는 방법입니다.

 

<?php

// connect

 $m = new Mongo();

 

// select a database

$db = $m->admin;

 

// authentication

$db->authenticate(“system″,”manager″);

 

// shutdown

$db->command(array(“shutdown”=>1));

……


** 상기 방법이외에 커맨드 창에서 아래와 같이 shutdown 옵션을 이용하는 것도 가능합니다.

ex)# mongod --shutdown --dbpath /home/mongodb/database

 



'IT노트 > MongoDB' 카테고리의 다른 글

10/07월 빅데이터  (0) 2015.03.21
10월10일 빅데이터교육  (0) 2015.03.16
mongoDB 자료 게시판 목록  (0) 2015.02.03
2.1 MongoDB 사용자의 생성과 관리  (0) 2015.02.03
2장. MongoDB의 시작과 종료  (0) 2015.02.03
Posted by wychoi
,