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

Paperjs presentation
Paperjs presentationPaperjs presentation
Paperjs presentation
sharp-blade
 
An Introduction to Tinkerpop
An Introduction to TinkerpopAn Introduction to Tinkerpop
An Introduction to Tinkerpop
Takahiro Inoue
 
Travel management
Travel managementTravel management
Travel management
1Parimal2
 
Full-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.jsFull-Stack JavaScript with Node.js
Full-Stack JavaScript with Node.js
Michael Lehmann
 
JavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovyJavaSE7 Launch Event: Java7xGroovy
JavaSE7 Launch Event: Java7xGroovy
Yasuharu Nakano
 

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

웹툰 플랫폼의 진화와 한국 웹툰의 미래
웹툰 플랫폼의 진화와 한국 웹툰의 미래웹툰 플랫폼의 진화와 한국 웹툰의 미래
웹툰 플랫폼의 진화와 한국 웹툰의 미래
Chang Kim
 
Présentation marché coréen
Présentation marché coréenPrésentation marché coréen
Présentation marché coréen
cciducher
 
[뉴에프오] “웹툰 + TV 애니메이션 + 소셜게임” = 와라편의점
[뉴에프오] “웹툰 + TV 애니메이션 + 소셜게임” = 와라편의점  [뉴에프오] “웹툰 + TV 애니메이션 + 소셜게임” = 와라편의점
[뉴에프오] “웹툰 + TV 애니메이션 + 소셜게임” = 와라편의점
GAMENEXT Works
 

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
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
Abed 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
 
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
Josh Mock
 
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
Moriyoshi Koizumi
 
Html and i_phone_mobile-2
Html and i_phone_mobile-2Html and i_phone_mobile-2
Html and i_phone_mobile-2
tonvanbart
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 

Similaire à 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
 

Plus de 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

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

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/