yum 경로에 아래 파일 생성


아래 운영체제 비트에 따라 설치! (주의: 잘못된 비트일 경우 실행안됨;)

Mongodb-repo for Fedora 18/17/16/15/14/13/12, CentOS 6.4/5.9 and Red Hat (RHEL) 6.4/5.9 on i686 (32-bit)

name=10gen Repository

Mongodb-repo for Fedora 18/17/15/14/13/12, CentOS 6.4/5.9 and Red Hat (RHEL) 6.4/5.9 on x86_64 (64-bit)

name=10gen Repository

Install stable version of MongoDB

yum install mongo-10gen mongo-10gen-server


2. Configure MongoDB Database Server

2.1 Edit /etc/mongod.conf file:

nano -w /etc/mongod.conf

2.2 Check and set basic settings, before starting MongoDB (default settings are good)


2.3 Start MongoDB Server

service mongod start
## OR ##
/etc/init.d/mongod start

2.4 Start MongoDB on boot

chkconfig --levels 235 mongod on

3. Test MongoDB Server

3.1 Open MongoDB Command Line Client


3.2 Save, Update and Find Some Test Data on MongoDB

> use test
switched to db test
> db.foo.find()
> db.foo.save({a: 1})
> db.foo.find()
{ "_id" : ObjectId("4b8ed53c4f450867bb35a1a9"), "a" : 1 }
> db.foo.update( {a: 1}, {a: 5})
> db.foo.find()
{ "_id" : ObjectId("4b8ed53c4f450867bb35a1a9"), "a" : 5 }

node mongolian (npm install mongolian)

var Mongolian = require("mongolian");
var server = new Mongolian;

var db = server.db("test"); // test Database선택
var posts = db.collection("posts"); //posts Collection 선택

//posts Collection 에  Document 넣기
    pageId: "hallo",
    title: "Hallo",
    created: new Date,
    body: "Welcome to my new blog!"

node mongoose 테스트 (npm install mongoose)

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

// localhost 에 testdb Database에 접속

//모델의 스키마를 작성한다
var CommentSchema = new Schema({
    desc : String,  //내용
    hit : Number,   //조회수
    date : Date     //작성일

// CommentSchema에 맞는 CommentModel 만들기
// comment는 Document , 자동으로 comments Collection 에 모델이 저장된
var CommentModel = mongoose.model('comment', CommentSchema);

//CommentModel의 인스턴스생성
var comment = new CommentModel();

//인스턴스에 값을 할당하고
comment.desc = "nodejs test";
comment.hit = 0;
comment.date = new Date();

//저장하면 바로 몽고db에 올라간다
comment.save(function (err) {
    if (!err) console.log('Success!');

mongodb의 설정파일(/etc/mongod.conf) 디폴트 내용 

# mongod.conf
#where to log
# fork and run in background
# location of pidfile
# Listen to local interface only. Comment out to listen on all interfaces.
# Disables write-ahead journaling
# nojournal=true
# Enables periodic logging of CPU utilization and I/O wait
# Turn on/off security. Off is currently the default
# Verbose logging output.
# Inspect all client data for validity on receipt (useful for
# developing drivers)
# Enable db quota management
# Set oplogging level where n is
# 0=off (default)
# 1=W
# 2=R
# 3=both
# 7=W+some reads
# Ignore query hints
# Disable the HTTP interface (Defaults to localhost:27018).
# Turns off server-side scripting. This will result in greatly limited
# functionality
# Turns off table scans. Any query that would do a table scan fails.
# Disable data file preallocation.
# Specify .ns file size for new databases.
# nssize=<size>
# Replication Options
# in replicated mongo databases, specify the replica set name here
# maximum size in megabytes for replication operation log
# path to a key file storing authentication info for connections
# between replica set members

mongodb 설치된곳

# cd /var/lib/mongo

mongodb DB데이터 저장되는 곳

# mongod --dbpath /var/lib/mongo/journal


MongoDB shell version: 2.6.12

connecting to: test

2018-08-24T16:55:27.282+0900 warning: Failed to connect to, reason: errno:111 Connection refused

2018-08-24T16:55:27.282+0900 Error: couldn't connect to server (, connection attempt failed at src/mongo/shell/mongo.js:146

exception: connect failed

위와 같은 오류가 발생하면, 공간이 부족하거나, 서버재시작으로 mongod가 서비스되고 있지 않고 있기 때문이다.

# mongod

# mongod --dbpath /var/lib/mongo/journal

명령을 통해 실행!