SlideShare une entreprise Scribd logo
1  sur  18
MongoDB    Ch 6. Aggregation 아키텍트를 꿈꾸는 사람들cafe.naver.com/architect1 현수명  soomong.net #soomong
Count Distinct Group MapReduce
Count > db.foo.find() { "_id" : ObjectId(“4e2…"), "bar" : "baz" } { "_id" : ObjectId(“4e2…"), "a" : "abc" } { "_id" : ObjectId(“4e2…"), "ohho" : "hohohohoho" } { "_id" : ObjectId(“4e2…"), "123456" : "gooood" } > db.foo.count() 4
Count > db.foo.insert({"x":2}) > db.foo.count() 5
Count+ > db.foo.count function (x) {     return this.find(x).count(); > db.foo.count = 0 0 > db.foo.count() Mon Jul 25 00:13:19 TypeError:  db.foo.count is not a function (shell):1
Distinct > db.foo.find() { "_id" : ObjectId(“4e2…"), "bar" : "baz" } { "_id" : ObjectId(“4e2…"), "a" : "abc" } { "_id" : ObjectId(“4e2…"), "ohho" : "hohohohoho" } { "_id" : ObjectId(“4e2…"), "123456" : "gooood" } > db.runCommand({"distinct":"foo","key":"ohho"}) {         "values" : [                 "hohohohoho"         ],         "stats" : {                 "n" : 5,                 "nscanned" : 5,                 "nscannedObjects" : 5,                 "timems" : 1         },         "ok" : 1 }
Distinct+ > db.runCommand function (obj) {     if (typeofobj == "string") { var n = {};         n[obj] = 1; obj = n;     }     return this.getCollection("$cmd").findOne(obj); } > db.foo.runCommand function (cmd, params) {     if (typeofcmd == "object") {         return this._db._dbCommand(cmd);     } var c = {};     c[cmd] = this.getName();     if (params) { Object.extend(c, params);     }     return this._db._dbCommand(c); }
Group > db.stocks.find() { "_id" : ObjectId(“…"), "day" : "2011/07/25",  "time" : “2011/07/25 01:00:00 GMT-400", "price" : 4.23 } { "_id" : ObjectId(“…"), "day" : "2011/07/26",  "time" : “2011/07/26 11:05:00 GMT-400", "price" : 4.27 } { "_id" : ObjectId(“…"), "day" : "2011/07/25",  "time" : “2011/07/25 03:47:00 GMT-400", "price" : 4.1 } { "_id" : ObjectId(“…"), "day" : "2011/07/28",  "time" : “2011/07/28 05:27:38 GMT-400", "price" : 4.3 } { "_id" : ObjectId(“…"), "day" : "2011/07/26",  "time" : “2011/07/26 06:34:50 GMT-400", "price" : 4.01 } {"time" : “2011/07/25 03:47:00 GMT-400", "price" : 4.1 } {"time" : “2011/07/26 11:05:00 GMT-400", "price" : 4.27 } {"time" : “2011/07/28 05:27:38 GMT-400", "price" : 4.3 }
Group > db.runCommand({"group" : { ... "ns" : "stocks", ... "key" : "day", ... "initial" : {"time" : 0}, ... "$reduce" : function(doc, prev) { ... 	if (doc.time > prev.time) { ... 		prev.price = doc.price; ... 		prev.time = doc.time; ... 	} ... }}}) {"time" : “2011/07/25 03:47:00 GMT-400", "price" : 4.1 } {"time" : “2011/07/26 11:05:00 GMT-400", "price" : 4.27 } {"time" : “2011/07/28 05:27:38 GMT-400", "price" : 4.3 }
Group "ns" : Collection "key" : 묶고싶은 Key "initial" : reduce 연산의 초기값 " $ , $reduce" : reduce 연산 "condition" : 조건 "finalize" : 마지막에 한번만 수행 "$keyf" : 키를 함수로
MapReduce 문제를 분할 각 청크를 다른 서버로 각 서버가 처리후 결과 모으기 장점 쉽게 병렬화 단점 복잡타
Map 컬렉션내에 각 키가 몇번씩 나타나는지 세어보자 map = function () {     for (var key in this) { emit(key, {count:1});     }
Reduce reduce = function (key, emits) {     total = 0;     for (vari in emits) { total += emits[i].count;     }     return {count:total};
Execution mr = db.foo.mapReduce (map,reduce,{out:"mongoDBmapReduce"}) {         "result" : "mongoDBmapReduce",         "timeMillis" : 11,         "counts" : {                 "input" : 4,                 "emit" : 8,                 "output" : 5         },         "ok" : 1, } input : 맵함수로 보내진 문서수 emit : 맵 함수에서 호출한 emit 수 Output : 결과 컬렉션에 생성된 문서수
MapReduce Parallelism As of right now, MapReduce jobs on a single mongod process are single threaded.  This is due to a design limitationin current JavaScript engines.  We are looking into alternatives to solve this issue,  but for now if you want to parallelize your MapReduce jobs,  you will need to either use shardingor  do the aggregation client-side in your code.
Reference MongoDB완벽 가이드 -한빛미디어 http://www.mongodb.org/ http://www.coolinfographics.com/
감사합니다

Contenu connexe

Tendances (19)

JavaScript - Agora nervoso
JavaScript - Agora nervosoJavaScript - Agora nervoso
JavaScript - Agora nervoso
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentation
 
Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016Powered by Python - PyCon Germany 2016
Powered by Python - PyCon Germany 2016
 
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
 
An Introduction to Tinkerpop
An Introduction to TinkerpopAn Introduction to Tinkerpop
An Introduction to Tinkerpop
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
 
C programs
C programsC programs
C programs
 
ECMAScript 5: Новое в JavaScript
ECMAScript 5: Новое в JavaScriptECMAScript 5: Новое в JavaScript
ECMAScript 5: Новое в JavaScript
 
Pointer level 2
Pointer   level 2Pointer   level 2
Pointer level 2
 
Cluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in PracticeCluj Big Data Meetup - Big Data in Practice
Cluj Big Data Meetup - Big Data in Practice
 
Travel management
Travel managementTravel management
Travel management
 
LLVM Backend の紹介
LLVM Backend の紹介LLVM Backend の紹介
LLVM Backend の紹介
 
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsFull-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.js
 
c++ project on restaurant billing
c++ project on restaurant billing c++ project on restaurant billing
c++ project on restaurant billing
 
Snow
SnowSnow
Snow
 
Ee
EeEe
Ee
 
Arp
ArpArp
Arp
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
 

En vedette

네이버 웹툰 다운로더
네이버 웹툰 다운로더네이버 웹툰 다운로더
네이버 웹툰 다운로더Soobin Jung
 
웹툰 플랫폼의 진화와 한국 웹툰의 미래
웹툰 플랫폼의 진화와 한국 웹툰의 미래웹툰 플랫폼의 진화와 한국 웹툰의 미래
웹툰 플랫폼의 진화와 한국 웹툰의 미래Chang Kim
 
LeasingBook Mobile Leasing Application
LeasingBook Mobile Leasing ApplicationLeasingBook Mobile Leasing Application
LeasingBook Mobile Leasing ApplicationBecca Wilson
 
Project center in trichy @ieee 2016 17 titles for java and dotnet
Project center in trichy @ieee 2016 17 titles for java and dotnetProject center in trichy @ieee 2016 17 titles for java and dotnet
Project center in trichy @ieee 2016 17 titles for java and dotnetElakkiya Triplen
 
Project center in trichy @ieee 2016 17 titles for java and dotnet
Project center in trichy @ieee 2016 17 titles for java and dotnetProject center in trichy @ieee 2016 17 titles for java and dotnet
Project center in trichy @ieee 2016 17 titles for java and dotnetElakkiya Triplen
 
Présentation marché coréen
Présentation marché coréenPrésentation marché coréen
Présentation marché coréencciducher
 
Cay Kazanlari
Cay KazanlariCay Kazanlari
Cay KazanlariCafemarkt
 
[뉴에프오] “웹툰 + TV 애니메이션 + 소셜게임” = 와라편의점
[뉴에프오] “웹툰 + TV 애니메이션 + 소셜게임” = 와라편의점  [뉴에프오] “웹툰 + TV 애니메이션 + 소셜게임” = 와라편의점
[뉴에프오] “웹툰 + TV 애니메이션 + 소셜게임” = 와라편의점 GAMENEXT Works
 
Trend report 웹툰 콘텐츠의 지속적인 성장 및 광고플랫폼적 가치
Trend report 웹툰 콘텐츠의 지속적인 성장 및 광고플랫폼적 가치Trend report 웹툰 콘텐츠의 지속적인 성장 및 광고플랫폼적 가치
Trend report 웹툰 콘텐츠의 지속적인 성장 및 광고플랫폼적 가치Nasmedia
 
[111] 네이버효과툰어떻게만들어졌나
[111] 네이버효과툰어떻게만들어졌나[111] 네이버효과툰어떻게만들어졌나
[111] 네이버효과툰어떻게만들어졌나NAVER D2
 

En vedette (15)

Corée du sud
Corée du sudCorée du sud
Corée du sud
 
네이버 웹툰 다운로더
네이버 웹툰 다운로더네이버 웹툰 다운로더
네이버 웹툰 다운로더
 
웹툰 플랫폼의 진화와 한국 웹툰의 미래
웹툰 플랫폼의 진화와 한국 웹툰의 미래웹툰 플랫폼의 진화와 한국 웹툰의 미래
웹툰 플랫폼의 진화와 한국 웹툰의 미래
 
FireShot Capture 10 - Why Retailers Should Outsource Their Analytics-Kai Clar...
FireShot Capture 10 - Why Retailers Should Outsource Their Analytics-Kai Clar...FireShot Capture 10 - Why Retailers Should Outsource Their Analytics-Kai Clar...
FireShot Capture 10 - Why Retailers Should Outsource Their Analytics-Kai Clar...
 
LeasingBook Mobile Leasing Application
LeasingBook Mobile Leasing ApplicationLeasingBook Mobile Leasing Application
LeasingBook Mobile Leasing Application
 
afstudeeropdracht
afstudeeropdrachtafstudeeropdracht
afstudeeropdracht
 
Project center in trichy @ieee 2016 17 titles for java and dotnet
Project center in trichy @ieee 2016 17 titles for java and dotnetProject center in trichy @ieee 2016 17 titles for java and dotnet
Project center in trichy @ieee 2016 17 titles for java and dotnet
 
Job Responsibilities
Job ResponsibilitiesJob Responsibilities
Job Responsibilities
 
Project center in trichy @ieee 2016 17 titles for java and dotnet
Project center in trichy @ieee 2016 17 titles for java and dotnetProject center in trichy @ieee 2016 17 titles for java and dotnet
Project center in trichy @ieee 2016 17 titles for java and dotnet
 
Présentation marché coréen
Présentation marché coréenPrésentation marché coréen
Présentation marché coréen
 
Cay Kazanlari
Cay KazanlariCay Kazanlari
Cay Kazanlari
 
[뉴에프오] “웹툰 + TV 애니메이션 + 소셜게임” = 와라편의점
[뉴에프오] “웹툰 + TV 애니메이션 + 소셜게임” = 와라편의점  [뉴에프오] “웹툰 + TV 애니메이션 + 소셜게임” = 와라편의점
[뉴에프오] “웹툰 + TV 애니메이션 + 소셜게임” = 와라편의점
 
Trend report 웹툰 콘텐츠의 지속적인 성장 및 광고플랫폼적 가치
Trend report 웹툰 콘텐츠의 지속적인 성장 및 광고플랫폼적 가치Trend report 웹툰 콘텐츠의 지속적인 성장 및 광고플랫폼적 가치
Trend report 웹툰 콘텐츠의 지속적인 성장 및 광고플랫폼적 가치
 
Donald-Kuhlmann
Donald-KuhlmannDonald-Kuhlmann
Donald-Kuhlmann
 
[111] 네이버효과툰어떻게만들어졌나
[111] 네이버효과툰어떻게만들어졌나[111] 네이버효과툰어떻게만들어졌나
[111] 네이버효과툰어떻게만들어졌나
 

Similaire à MongoDB

development, ruby, conferences, frameworks, ruby on rails, confreaks, actsasc...
development, ruby, conferences, frameworks, ruby on rails, confreaks, actsasc...development, ruby, conferences, frameworks, ruby on rails, confreaks, actsasc...
development, ruby, conferences, frameworks, ruby on rails, confreaks, actsasc...ActsAsCon
 
Relaxing With CouchDB
Relaxing With CouchDBRelaxing With CouchDB
Relaxing With CouchDBleinweber
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)MongoSF
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - GuilinJackson Tian
 
2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDBantoinegirbal
 
MongoDB dla administratora
MongoDB dla administratora MongoDB dla administratora
MongoDB dla administratora 3camp
 
Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011Scalac
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Introzhang tao
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs偉格 高
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeJosh Mock
 
How data rules the world: Telemetry in Battlefield Heroes
How data rules the world: Telemetry in Battlefield HeroesHow data rules the world: Telemetry in Battlefield Heroes
How data rules the world: Telemetry in Battlefield HeroesElectronic Arts / DICE
 
PostgreSQLからMongoDBへ
PostgreSQLからMongoDBへPostgreSQLからMongoDBへ
PostgreSQLからMongoDBへBasuke Suzuki
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2goMoriyoshi Koizumi
 
Html and i_phone_mobile-2
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2tonvanbart
 
Python And GIS - Beyond Modelbuilder And Pythonwin
Python And GIS - Beyond Modelbuilder And PythonwinPython And GIS - Beyond Modelbuilder And Pythonwin
Python And GIS - Beyond Modelbuilder And PythonwinChad Cooper
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRick Copeland
 

Similaire à MongoDB (20)

Groovy
GroovyGroovy
Groovy
 
development, ruby, conferences, frameworks, ruby on rails, confreaks, actsasc...
development, ruby, conferences, frameworks, ruby on rails, confreaks, actsasc...development, ruby, conferences, frameworks, ruby on rails, confreaks, actsasc...
development, ruby, conferences, frameworks, ruby on rails, confreaks, actsasc...
 
Relaxing With CouchDB
Relaxing With CouchDBRelaxing With CouchDB
Relaxing With CouchDB
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
 
2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB
 
MongoDB dla administratora
MongoDB dla administratora MongoDB dla administratora
MongoDB dla administratora
 
Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011
 
Mongo db dla administratora
Mongo db dla administratoraMongo db dla administratora
Mongo db dla administratora
 
Ruby on Rails Intro
Ruby on Rails IntroRuby on Rails Intro
Ruby on Rails Intro
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
Unit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and NodeUnit testing JavaScript using Mocha and Node
Unit testing JavaScript using Mocha and Node
 
How data rules the world: Telemetry in Battlefield Heroes
How data rules the world: Telemetry in Battlefield HeroesHow data rules the world: Telemetry in Battlefield Heroes
How data rules the world: Telemetry in Battlefield Heroes
 
PostgreSQLからMongoDBへ
PostgreSQLからMongoDBへPostgreSQLからMongoDBへ
PostgreSQLからMongoDBへ
 
All I know about rsc.io/c2go
All I know about rsc.io/c2goAll I know about rsc.io/c2go
All I know about rsc.io/c2go
 
Html and i_phone_mobile-2
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2
 
Python And GIS - Beyond Modelbuilder And Pythonwin
Python And GIS - Beyond Modelbuilder And PythonwinPython And GIS - Beyond Modelbuilder And Pythonwin
Python And GIS - Beyond Modelbuilder And Pythonwin
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 

Plus de hyun soomyung

Scalable Web Architecture and Distributed Systems
Scalable Web Architecture and Distributed SystemsScalable Web Architecture and Distributed Systems
Scalable Web Architecture and Distributed Systemshyun soomyung
 
Dependency Breaking Techniques
Dependency Breaking TechniquesDependency Breaking Techniques
Dependency Breaking Techniqueshyun soomyung
 
아꿈사 매니저소개
아꿈사 매니저소개아꿈사 매니저소개
아꿈사 매니저소개hyun soomyung
 
HTML5 & CSS3 - Video,Audio
HTML5 & CSS3 - Video,AudioHTML5 & CSS3 - Video,Audio
HTML5 & CSS3 - Video,Audiohyun soomyung
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Designhyun soomyung
 
The Art of Computer Programming 2.4 다중연결구조
The Art of Computer Programming 2.4 다중연결구조The Art of Computer Programming 2.4 다중연결구조
The Art of Computer Programming 2.4 다중연결구조hyun soomyung
 
The Art of Computer Programming 2.3.2 Tree
The Art of Computer Programming 2.3.2 TreeThe Art of Computer Programming 2.3.2 Tree
The Art of Computer Programming 2.3.2 Treehyun soomyung
 
Design Pattern - Multithread Ch10
Design Pattern - Multithread Ch10Design Pattern - Multithread Ch10
Design Pattern - Multithread Ch10hyun soomyung
 
The Art of Computer Programming 1.3.2 MIXAL
The Art of Computer Programming 1.3.2 MIXALThe Art of Computer Programming 1.3.2 MIXAL
The Art of Computer Programming 1.3.2 MIXALhyun soomyung
 
The Art of Computer Programming 1.2.5
The Art of Computer Programming 1.2.5The Art of Computer Programming 1.2.5
The Art of Computer Programming 1.2.5hyun soomyung
 
스터디그룹 패턴 (A PATTERN LANGUAGE FOR STUDY GROUPS)
스터디그룹 패턴 (A PATTERN LANGUAGE FOR STUDY GROUPS)스터디그룹 패턴 (A PATTERN LANGUAGE FOR STUDY GROUPS)
스터디그룹 패턴 (A PATTERN LANGUAGE FOR STUDY GROUPS)hyun soomyung
 
프로그래머의 길,멘토에게 묻다 2장
프로그래머의 길,멘토에게 묻다 2장프로그래머의 길,멘토에게 묻다 2장
프로그래머의 길,멘토에게 묻다 2장hyun soomyung
 
[페차쿠차] 배움의 기술
[페차쿠차] 배움의 기술[페차쿠차] 배움의 기술
[페차쿠차] 배움의 기술hyun soomyung
 
실전 윈도우 디버깅. Ch3. 디버거 해부
실전 윈도우 디버깅. Ch3. 디버거 해부실전 윈도우 디버깅. Ch3. 디버거 해부
실전 윈도우 디버깅. Ch3. 디버거 해부hyun soomyung
 
xUnitTestPattern/chapter8
xUnitTestPattern/chapter8xUnitTestPattern/chapter8
xUnitTestPattern/chapter8hyun soomyung
 
예제로 보는 Pattern 연상법
예제로 보는 Pattern 연상법예제로 보는 Pattern 연상법
예제로 보는 Pattern 연상법hyun soomyung
 
프로그램은 왜 실패하는가?
프로그램은 왜 실패하는가?프로그램은 왜 실패하는가?
프로그램은 왜 실패하는가?hyun soomyung
 

Plus de hyun soomyung (20)

Scalable Web Architecture and Distributed Systems
Scalable Web Architecture and Distributed SystemsScalable Web Architecture and Distributed Systems
Scalable Web Architecture and Distributed Systems
 
Dependency Breaking Techniques
Dependency Breaking TechniquesDependency Breaking Techniques
Dependency Breaking Techniques
 
아꿈사 매니저소개
아꿈사 매니저소개아꿈사 매니저소개
아꿈사 매니저소개
 
HTML5 & CSS3 - Video,Audio
HTML5 & CSS3 - Video,AudioHTML5 & CSS3 - Video,Audio
HTML5 & CSS3 - Video,Audio
 
Hybrid app
Hybrid appHybrid app
Hybrid app
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
MapReduce
MapReduceMapReduce
MapReduce
 
The Art of Computer Programming 2.4 다중연결구조
The Art of Computer Programming 2.4 다중연결구조The Art of Computer Programming 2.4 다중연결구조
The Art of Computer Programming 2.4 다중연결구조
 
The Art of Computer Programming 2.3.2 Tree
The Art of Computer Programming 2.3.2 TreeThe Art of Computer Programming 2.3.2 Tree
The Art of Computer Programming 2.3.2 Tree
 
Design Pattern - Multithread Ch10
Design Pattern - Multithread Ch10Design Pattern - Multithread Ch10
Design Pattern - Multithread Ch10
 
The Art of Computer Programming 1.3.2 MIXAL
The Art of Computer Programming 1.3.2 MIXALThe Art of Computer Programming 1.3.2 MIXAL
The Art of Computer Programming 1.3.2 MIXAL
 
The Art of Computer Programming 1.2.5
The Art of Computer Programming 1.2.5The Art of Computer Programming 1.2.5
The Art of Computer Programming 1.2.5
 
스터디그룹 패턴 (A PATTERN LANGUAGE FOR STUDY GROUPS)
스터디그룹 패턴 (A PATTERN LANGUAGE FOR STUDY GROUPS)스터디그룹 패턴 (A PATTERN LANGUAGE FOR STUDY GROUPS)
스터디그룹 패턴 (A PATTERN LANGUAGE FOR STUDY GROUPS)
 
Clojure Chapter.6
Clojure Chapter.6Clojure Chapter.6
Clojure Chapter.6
 
프로그래머의 길,멘토에게 묻다 2장
프로그래머의 길,멘토에게 묻다 2장프로그래머의 길,멘토에게 묻다 2장
프로그래머의 길,멘토에게 묻다 2장
 
[페차쿠차] 배움의 기술
[페차쿠차] 배움의 기술[페차쿠차] 배움의 기술
[페차쿠차] 배움의 기술
 
실전 윈도우 디버깅. Ch3. 디버거 해부
실전 윈도우 디버깅. Ch3. 디버거 해부실전 윈도우 디버깅. Ch3. 디버거 해부
실전 윈도우 디버깅. Ch3. 디버거 해부
 
xUnitTestPattern/chapter8
xUnitTestPattern/chapter8xUnitTestPattern/chapter8
xUnitTestPattern/chapter8
 
예제로 보는 Pattern 연상법
예제로 보는 Pattern 연상법예제로 보는 Pattern 연상법
예제로 보는 Pattern 연상법
 
프로그램은 왜 실패하는가?
프로그램은 왜 실패하는가?프로그램은 왜 실패하는가?
프로그램은 왜 실패하는가?
 

Dernier

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 

Dernier (20)

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 

MongoDB

  • 1. MongoDB Ch 6. Aggregation 아키텍트를 꿈꾸는 사람들cafe.naver.com/architect1 현수명 soomong.net #soomong
  • 3. Count > db.foo.find() { "_id" : ObjectId(“4e2…"), "bar" : "baz" } { "_id" : ObjectId(“4e2…"), "a" : "abc" } { "_id" : ObjectId(“4e2…"), "ohho" : "hohohohoho" } { "_id" : ObjectId(“4e2…"), "123456" : "gooood" } > db.foo.count() 4
  • 4. Count > db.foo.insert({"x":2}) > db.foo.count() 5
  • 5. Count+ > db.foo.count function (x) { return this.find(x).count(); > db.foo.count = 0 0 > db.foo.count() Mon Jul 25 00:13:19 TypeError: db.foo.count is not a function (shell):1
  • 6. Distinct > db.foo.find() { "_id" : ObjectId(“4e2…"), "bar" : "baz" } { "_id" : ObjectId(“4e2…"), "a" : "abc" } { "_id" : ObjectId(“4e2…"), "ohho" : "hohohohoho" } { "_id" : ObjectId(“4e2…"), "123456" : "gooood" } > db.runCommand({"distinct":"foo","key":"ohho"}) { "values" : [ "hohohohoho" ], "stats" : { "n" : 5, "nscanned" : 5, "nscannedObjects" : 5, "timems" : 1 }, "ok" : 1 }
  • 7. Distinct+ > db.runCommand function (obj) { if (typeofobj == "string") { var n = {}; n[obj] = 1; obj = n; } return this.getCollection("$cmd").findOne(obj); } > db.foo.runCommand function (cmd, params) { if (typeofcmd == "object") { return this._db._dbCommand(cmd); } var c = {}; c[cmd] = this.getName(); if (params) { Object.extend(c, params); } return this._db._dbCommand(c); }
  • 8. Group > db.stocks.find() { "_id" : ObjectId(“…"), "day" : "2011/07/25", "time" : “2011/07/25 01:00:00 GMT-400", "price" : 4.23 } { "_id" : ObjectId(“…"), "day" : "2011/07/26", "time" : “2011/07/26 11:05:00 GMT-400", "price" : 4.27 } { "_id" : ObjectId(“…"), "day" : "2011/07/25", "time" : “2011/07/25 03:47:00 GMT-400", "price" : 4.1 } { "_id" : ObjectId(“…"), "day" : "2011/07/28", "time" : “2011/07/28 05:27:38 GMT-400", "price" : 4.3 } { "_id" : ObjectId(“…"), "day" : "2011/07/26", "time" : “2011/07/26 06:34:50 GMT-400", "price" : 4.01 } {"time" : “2011/07/25 03:47:00 GMT-400", "price" : 4.1 } {"time" : “2011/07/26 11:05:00 GMT-400", "price" : 4.27 } {"time" : “2011/07/28 05:27:38 GMT-400", "price" : 4.3 }
  • 9. Group > db.runCommand({"group" : { ... "ns" : "stocks", ... "key" : "day", ... "initial" : {"time" : 0}, ... "$reduce" : function(doc, prev) { ... if (doc.time > prev.time) { ... prev.price = doc.price; ... prev.time = doc.time; ... } ... }}}) {"time" : “2011/07/25 03:47:00 GMT-400", "price" : 4.1 } {"time" : “2011/07/26 11:05:00 GMT-400", "price" : 4.27 } {"time" : “2011/07/28 05:27:38 GMT-400", "price" : 4.3 }
  • 10. Group "ns" : Collection "key" : 묶고싶은 Key "initial" : reduce 연산의 초기값 " $ , $reduce" : reduce 연산 "condition" : 조건 "finalize" : 마지막에 한번만 수행 "$keyf" : 키를 함수로
  • 11. MapReduce 문제를 분할 각 청크를 다른 서버로 각 서버가 처리후 결과 모으기 장점 쉽게 병렬화 단점 복잡타
  • 12. Map 컬렉션내에 각 키가 몇번씩 나타나는지 세어보자 map = function () { for (var key in this) { emit(key, {count:1}); }
  • 13. Reduce reduce = function (key, emits) { total = 0; for (vari in emits) { total += emits[i].count; } return {count:total};
  • 14. Execution mr = db.foo.mapReduce (map,reduce,{out:"mongoDBmapReduce"}) { "result" : "mongoDBmapReduce", "timeMillis" : 11, "counts" : { "input" : 4, "emit" : 8, "output" : 5 }, "ok" : 1, } input : 맵함수로 보내진 문서수 emit : 맵 함수에서 호출한 emit 수 Output : 결과 컬렉션에 생성된 문서수
  • 15.
  • 16. MapReduce Parallelism As of right now, MapReduce jobs on a single mongod process are single threaded. This is due to a design limitationin current JavaScript engines. We are looking into alternatives to solve this issue, but for now if you want to parallelize your MapReduce jobs, you will need to either use shardingor do the aggregation client-side in your code.
  • 17. Reference MongoDB완벽 가이드 -한빛미디어 http://www.mongodb.org/ http://www.coolinfographics.com/