1. 개요

MongoDB (몽고DB) 간단 데이터 넣기 (insert)

 

2. 절차

2-1. MongoDB 접속

$ mongo
MongoDB shell version v3.4.7
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.7
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
Server has startup warnings:
2017-08-21T00:46:56.293+0000 I STORAGE  [initandlisten]
2017-08-21T00:46:56.293+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-08-21T00:46:56.293+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-08-21T00:46:56.338+0000 I CONTROL  [initandlisten]
2017-08-21T00:46:56.338+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-08-21T00:46:56.338+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-08-21T00:46:56.338+0000 I CONTROL  [initandlisten]
>

몇가지 경고가 나오네요. 일단 무시합니다.

 

2-2. 데이터베이스 생성

이름은 test_database라고 합니다.

> use test_database
switched to db test_database

 잘 생성되었는지 DB 목록을 확인합니다.

> show dbs
admin  0.000GB
local  0.000GB

그런데 내가 만든 test_database가 보이지 않습니다. 그 이유는 아직 아무것도 안들어있기 때문입니다.

어쨌든 현재 데이터베이스가 test_database가 맞는지 다시 한번 확인합니다.

> db
test_database

 

3-3. 데이터 삽입

이제 데이터를 넣습니다.

> db.emp.insert({"name":"stdio.h","phone":"010-1234-5678"});
WriteResult({ "nInserted" : 1 })

다시 데이터베이스 목록을 확인합니다.

> show dbs
admin          0.000GB
local          0.000GB
test_database  0.000GB
>