SlideShare uma empresa Scribd logo
1 de 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/
감사합니다

Mais conteúdo relacionado

Mais procurados

Mais procurados (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
 

Destaque

네이버 웹툰 다운로더
네이버 웹툰 다운로더네이버 웹툰 다운로더
네이버 웹툰 다운로더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
 

Destaque (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] 네이버효과툰어떻게만들어졌나
 

Semelhante a MongoDB

Relaxing With CouchDB
Relaxing With CouchDBRelaxing With CouchDB
Relaxing With CouchDBleinweber
 
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
 
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
 

Semelhante a MongoDB (20)

Groovy
GroovyGroovy
Groovy
 
Relaxing With CouchDB
Relaxing With CouchDBRelaxing With CouchDB
Relaxing With CouchDB
 
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...
 
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
 

Mais 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
 

Mais 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 연상법
 
프로그램은 왜 실패하는가?
프로그램은 왜 실패하는가?프로그램은 왜 실패하는가?
프로그램은 왜 실패하는가?
 

Último

Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
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
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 

Último (20)

Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
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.
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 

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/