Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mongo DB.

Similar presentations


Presentation on theme: "Mongo DB."— Presentation transcript:

1 Mongo DB

2 Contents 1주 2주 MongoDB Setup Data Structure Query Index Java Driver
Management 2주 Sharding GridFS MapReduce 분산 MongoDB 구축 실습 Java Application 개발 실습

3 Mongo DB MongoDB (from "humongous") is an open source, high-performance, schema-free, document-oriented database written in the C++ programming language Document-oriented storage Index Support Replication & High Availability Auto-Sharding Fast In-Place Updates Map/Reduce GridFS

4 Mongo DB Consistent UTF-8 encoding
Cross-platform support: Windows, Linux, OS X, and Solaris Type-rich: supports dates, regular expressions, code, binary data, and more (all BSON types) Cursors for query results Language Support : C++, Java, Haskell, JS, Ruby, PHP, Python

5 SQL to Mongo Mapping - Terminology
SQL Term Mongo Term Database Table Collection Index Row BSON Document Column BSON Field Primary Key Id field

6 Mongo DB System

7 Setup

8 Mongo DB 설치 버전 선택 플랫폼 선택 http://www.mongodb.org/display/DOCS/Downloads
짝수 : Stable (1.6.0, 1.6.1, 1.6,15 …) 홀수 : Experimental (1.7.0, 1.7.1, …) 플랫폼 선택 Mac OS X Linux Windows Mac OSX의 경우는 MacPorts등으로 설치 가능

9 Mongo DB 실행 실행 서비스 등록하기 DB file prealloc Linux나 Mac의 경우에도 동일
$cd > mongod.exe $cd > mongod.exe –dbpath C:\mydb\ 서비스 등록하기 $cd > mongod.exe –dbpath C:\mydb\ --install DB file prealloc $cd > mongod.exe --noprealloc Linux나 Mac의 경우에도 동일

10 Shell 쉘 띄우기 $cd> mongod.exe URL:PORT/dbname
$cd > mongod.exe –node Javascript등의 사용시 유용

11 Shell

12 Data Structure

13 Document {“greeting” : “Hello, world!”}
문서(Document)는 하나의 {Key, Value} set {“greeting” : “Hello, world!”} {“greeting” : “Hello, world!” , “foo” : 3} {“foo” : 3 , “greeting” : “Hello, world!”} Key .과 $는 예약어 _는 대부분 예약어 예약어를 제외한 어떠한 UTF-8 문자라도 사용 가능 Value mongoDB에서 지원하는 Data type

14 Collection 컬렉션(Collection)은 Document들의 모음 Schema를 정하지 않고 사용
서로 다른 구조의 Document를 한 Collection내에 저장할 수 있음 Collection별 관리 이유 개발 및 관리의 편의성 질의 속도 향상 효율적인 Index생성 {“greeting” : “Hello, world!”} {“foo” : 3} {“name” : “John”}

15 Database Database는 Collection들의 모음 Application 별로 Database를 분리하는 것을 권장
빈 문자열(“”)를 사용 불가 공백, ., $, \, \, null을 사용 불가 소문자만 사용 최대 64byte 길이 허용 Database의 이름이 DB파일명으로 저장

16

17 Data type null Boolean Int (32, 64) Double String {“x” : null}
{“x” : true} Int (32, 64) Javascript의 한계상 표현 불가능. 숫자를 입력할 경우 Double으로 간주 Double {“x” : 3.14} String {“x” : “foobar”}

18 Data type objectID Date Code (Javascript) Array Long 형
Document의 고유한 12byte ID임 {“x” : ObjectId()} Date Long 형 {“x” : new Date()} Code (Javascript) Javascript를 문서에 포함할 수 있음 {“x” : function() { /* … */ } Array 값의 집합이나 목록을 배열로 표현할 수 있음 {“x” : [“a”, “b”, “c”] }

19 Query

20 Insert / Delete Insert Delete Db.foo.insert({“bar” : “hello”})
Db.users.remove() : 해당 컬렉션(users)에 있는 모든 문서 삭제 Db.users.list.remove({“name” : “john”}) : 이름이 john인 모든 문서 삭제

21 Update

22 안전 연산 Insert, Remove, Update는 기본적으로 Fire and forget방식
해당 연산들의 수행 후 getLastError 명령어를 수행하여 반환 코드를 기다림 성능의 희생과 안전 사이에서 선택

23 Select db.collection.find({name: {first: 'John', last: 'Doe'}})
Find all documents in the collection with name of John Doe db.collection.find({name.last: 'Doe'}) Find all documents in the collection with last name of Doe db.collection.find({keywords: {$in: ['storage', 'DBMS']}}) Find all documents with 'storage' or 'DBMS' in its keywords array

24 질의 조건 Range, OR, Negation이 가능 비교연산자 OR Not %lt : < %lte : <=
%gt : > %gte : >= Start = new Date(“01/01/2007”) db.user.find({“registered” : {“$lt” : start}}) OR Db.c.find({“ticket_no” : {“$in” : [725, 542, 390]}}) Not Db.c.find({“ticket_no” : {$not” : {“$in” : [725,542,390]}})

25 Count, Distinct Count

26 Count, Distinct Distinct 주어진 키의 고유한 값들을 찾음
>db.runCommand({“distinct” : “people”, “key” : “age”})

27 SQL to Mongo Mapping - Query
CREATE TABLE USERS (a Number, b Number) db.createCollection(“USERS") INSERT INTO USERS VALUES(3,5) db.users.insert({a:3,b:5}) SELECT a,b FROM users db.users.find({}, {a:1,b:1}) SELECT * FROM users db.users.find() SELECT * FROM users WHERE age=33 db.users.find({age:33}) SELECT * FROM users WHERE age=33 ORDER BY name asc db.users.find({age:33}).sort({name:1}) SELECT * FROM users WHERE age>33 db.users.find({age:{$gt:33}}) SELECT * FROM users WHERE name LIKE "%Joe%" db.users.find({name:/Joe/}) UPDATE users SET a=1 WHERE b='q' db.users.update({b:'q'}, {$set:{a:1}}) DELETE FROM users WHERE z="abc" db.users.remove({z:'abc'});

28 Index

29 Indexing >db.people.find({“username” : “mark”})
>db.people.ensureIndex({“username” : 1}, {“background” : true)

30 Explain / Hint Explain Hint >db.foo.find().explain()
Result는 document의 형태 Hint >db.foo.find({“age” : 14}).hint({“username” : 1})

31 Spatial Index >db.map.ensureIndex({“gps” : “2d”})

32 Management

33 Logging File로의 Logging방법 >mongodb –logpath mongo.log

34 Monitoring Admin Console url:27017

35 Account

36 Java Drivers

37 Jar Github(http://www.github.com/mongodb/mongo-java-driver/downloads )
Com.mongodb 내부 클래스 사용

38

39 Next week.. Sharding를 통한 분산 구축 MapReduce 활용
MongoDB 구축, Java Application 개발 실습


Download ppt "Mongo DB."

Similar presentations


Ads by Google