SlideShare une entreprise Scribd logo
1  sur  12
Télécharger pour lire hors ligne
reactivemongo 
by david pichsenmeister
overview 
● fully non-blocking 
● asynchronous I/O operations 
● build against Akka 2.2 & 2.3 
● build against Scala 2.10 & 2.11
play! 2.3 plugin 
● support to play! 2.3 
● JSON <-> BSON conversion with 
embedded JSON library in play! 
● JSONCollection instead of 
ReactiveMongo’s BSONDocument
case class Pokemon( 
_id: BSONObjectID, 
name: String, 
category: String, 
moves: List[String] 
) 
object Pokemon { 
implicit val pokemonFormat: Format[Pokemon] = 
Json.format[Pokemon] 
}
object PokemonDAO { 
private def collectionName: String = "pokemon" 
private def db = ReactiveMongoPlugin.db 
private def collection = 
db[JSONCollection](collectionName)
def insert(pokemon: Pokemon): Future[LastError] = { 
collection.insert(Json.toJson(pokemon)) 
} 
def update(pokemon: Pokemon): Future[LastError] = { 
collection.update(BSONDocument("_id" -> pokemon._id), 
Json.toJson(pokemon)) 
} 
def remove(pokemon: Pokemon): Future[LastError] = { 
collection.remove(BSONDocument("_id" -> pokemon._id)) 
}
def findById(id: BSONObjectID): Future[Option[Pokemon] = { 
collection.find(BSONDocument("_id" -> 
id)).cursor[Pokemon].headOption 
} 
def findByCategory(cat: String): Future[List[Pokemon] = { 
collection.find(BSONDocument("category" -> 
cat)).options(QueryOpts(skipN = 0, batchSizeN 
= 10)).cursor[Pokemon].collect[List]() 
} 
def catchEmAll(): Future[List[Pokemon] = { 
collection.find(BSONDocument()). 
cursor[Pokemon].collect[List]() 
}
def update() = Action.async(parse.json) { 
// DON’T do this at home, kids!! 
val pokemon = Json.fromJson[Pokemon](request.body).get 
val future: Future =PokemonDAO.update(pokemon) 
future.map(lastError => { 
Accepted 
}) 
} 
controller
more features 
● GridFS as non-blocking, streaming 
datastore 
● Enumerator/Iteratee pattern to avoid 
huge memory usage
val cursor = collection.find(BSONDocument()).cursor[Pokemon] 
cursor.enumerate().apply(Iteratee.foreach { pokemon => 
println("found pokemon: " + pokemon.name) 
}) 
enumerator/iteratee
resources 
http://reactivemongo.org 
https://github.com/ReactiveMongo/Play-ReactiveMongo 
http://www.pokemon.com
thanks! 
feel free to add me on: 
.../3x14159265

Contenu connexe

Tendances

C# Development (Sam Corder)
C# Development (Sam Corder)C# Development (Sam Corder)
C# Development (Sam Corder)
MongoSF
 
Boom! Promises/A+ Was Born
Boom! Promises/A+ Was BornBoom! Promises/A+ Was Born
Boom! Promises/A+ Was Born
Domenic Denicola
 

Tendances (20)

Entity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net CoreEntity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net Core
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
Q
QQ
Q
 
"The little big project. From zero to hero in two weeks with 3 front-end engi...
"The little big project. From zero to hero in two weeks with 3 front-end engi..."The little big project. From zero to hero in two weeks with 3 front-end engi...
"The little big project. From zero to hero in two weeks with 3 front-end engi...
 
ActiveRecord
ActiveRecordActiveRecord
ActiveRecord
 
XForms and eXist: A Perfect Couple
XForms and eXist: A Perfect CoupleXForms and eXist: A Perfect Couple
XForms and eXist: A Perfect Couple
 
C# Development (Sam Corder)
C# Development (Sam Corder)C# Development (Sam Corder)
C# Development (Sam Corder)
 
Puerto serialarduino
Puerto serialarduinoPuerto serialarduino
Puerto serialarduino
 
Active Record
Active RecordActive Record
Active Record
 
Nginx cache api delete
Nginx cache api deleteNginx cache api delete
Nginx cache api delete
 
Boom! Promises/A+ Was Born
Boom! Promises/A+ Was BornBoom! Promises/A+ Was Born
Boom! Promises/A+ Was Born
 
The love child of Android and .NET: App development with Xamarin
The love child of Android and .NET: App development with XamarinThe love child of Android and .NET: App development with Xamarin
The love child of Android and .NET: App development with Xamarin
 
Json perl example
Json perl exampleJson perl example
Json perl example
 
QTP
QTPQTP
QTP
 
Building Java and Android apps on the blockchain
Building Java and Android apps on the blockchain Building Java and Android apps on the blockchain
Building Java and Android apps on the blockchain
 
Web3j 2.0 Update
Web3j 2.0 UpdateWeb3j 2.0 Update
Web3j 2.0 Update
 
Couchdb
CouchdbCouchdb
Couchdb
 
Javascript foundations: scope
Javascript foundations: scopeJavascript foundations: scope
Javascript foundations: scope
 
Membuat Form Login
Membuat Form Login Membuat Form Login
Membuat Form Login
 
Introduction to the new official C# Driver developed by 10gen
Introduction to the new official C# Driver developed by 10genIntroduction to the new official C# Driver developed by 10gen
Introduction to the new official C# Driver developed by 10gen
 

En vedette

Bot Trends 2017
Bot Trends 2017Bot Trends 2017
Bot Trends 2017
David Pichsenmeister
 

En vedette (20)

Telegram's Bot Platform
Telegram's Bot PlatformTelegram's Bot Platform
Telegram's Bot Platform
 
warp engine - an open source realtime push engine
warp engine - an open source realtime push enginewarp engine - an open source realtime push engine
warp engine - an open source realtime push engine
 
html5 web apps vs native apps
html5 web apps vs native appshtml5 web apps vs native apps
html5 web apps vs native apps
 
Bot Trends 2016
Bot Trends 2016Bot Trends 2016
Bot Trends 2016
 
Development and deployment of polyglot systems
Development and deployment of polyglot systemsDevelopment and deployment of polyglot systems
Development and deployment of polyglot systems
 
The Hitchhikers Guide To Html5 Offline Strategies (+firefoxOS)
The Hitchhikers Guide To Html5 Offline Strategies (+firefoxOS)The Hitchhikers Guide To Html5 Offline Strategies (+firefoxOS)
The Hitchhikers Guide To Html5 Offline Strategies (+firefoxOS)
 
Scala reflection
Scala reflectionScala reflection
Scala reflection
 
play! scala file resource handling and image resizing
play! scala file resource handling and image resizingplay! scala file resource handling and image resizing
play! scala file resource handling and image resizing
 
Will Chatbots kill apps? - Vienna Valley #7
Will Chatbots kill apps? - Vienna Valley #7Will Chatbots kill apps? - Vienna Valley #7
Will Chatbots kill apps? - Vienna Valley #7
 
Bot Trends 2017
Bot Trends 2017Bot Trends 2017
Bot Trends 2017
 
An Introduction to Chatbots
An Introduction to ChatbotsAn Introduction to Chatbots
An Introduction to Chatbots
 
Insights into Chatbot Development - Implementing Cross-Platform Chatbots
Insights into Chatbot Development - Implementing Cross-Platform ChatbotsInsights into Chatbot Development - Implementing Cross-Platform Chatbots
Insights into Chatbot Development - Implementing Cross-Platform Chatbots
 
알파고 해부하기 1부
알파고 해부하기 1부알파고 해부하기 1부
알파고 해부하기 1부
 
The lifecycle of a chatbot
The lifecycle of a chatbotThe lifecycle of a chatbot
The lifecycle of a chatbot
 
인공지능, 기계학습 그리고 딥러닝
인공지능, 기계학습 그리고 딥러닝인공지능, 기계학습 그리고 딥러닝
인공지능, 기계학습 그리고 딥러닝
 
쫄지말자딥러닝2 - CNN RNN 포함버전
쫄지말자딥러닝2 - CNN RNN 포함버전쫄지말자딥러닝2 - CNN RNN 포함버전
쫄지말자딥러닝2 - CNN RNN 포함버전
 
An Introduction To Chat Bots
An Introduction To Chat BotsAn Introduction To Chat Bots
An Introduction To Chat Bots
 
머신 러닝 입문 #1-머신러닝 소개와 kNN 소개
머신 러닝 입문 #1-머신러닝 소개와 kNN 소개머신 러닝 입문 #1-머신러닝 소개와 kNN 소개
머신 러닝 입문 #1-머신러닝 소개와 kNN 소개
 
알파고 (바둑 인공지능)의 작동 원리
알파고 (바둑 인공지능)의 작동 원리알파고 (바둑 인공지능)의 작동 원리
알파고 (바둑 인공지능)의 작동 원리
 
AlphaGo 알고리즘 요약
AlphaGo 알고리즘 요약AlphaGo 알고리즘 요약
AlphaGo 알고리즘 요약
 

Similaire à ReactiveMongo - non blocking and asynchronous I/O operations

San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
kchodorow
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problems
titanlambda
 
Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDB
Scott Hernandez
 

Similaire à ReactiveMongo - non blocking and asynchronous I/O operations (20)

Play + scala + reactive mongo
Play + scala + reactive mongoPlay + scala + reactive mongo
Play + scala + reactive mongo
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
 
Intorduction of Playframework
Intorduction of PlayframeworkIntorduction of Playframework
Intorduction of Playframework
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.
 
REST Web API with MongoDB
REST Web API with MongoDBREST Web API with MongoDB
REST Web API with MongoDB
 
Scala on Your Phone
Scala on Your PhoneScala on Your Phone
Scala on Your Phone
 
Http4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web StackHttp4s, Doobie and Circe: The Functional Web Stack
Http4s, Doobie and Circe: The Functional Web Stack
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problems
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source Database
 
Clojure functions
Clojure functionsClojure functions
Clojure functions
 
Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDB
 
Play 2.0
Play 2.0Play 2.0
Play 2.0
 
Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011
 
Using web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworksUsing web2py's DAL in other projects or frameworks
Using web2py's DAL in other projects or frameworks
 
How to React Native
How to React NativeHow to React Native
How to React Native
 
The What, Why And How of ClojureScript
The What, Why And How of ClojureScriptThe What, Why And How of ClojureScript
The What, Why And How of ClojureScript
 
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
 
Web Components With Rails
Web Components With RailsWeb Components With Rails
Web Components With Rails
 
jQuery
jQueryjQuery
jQuery
 

Plus de David Pichsenmeister

Plus de David Pichsenmeister (7)

Bots as Marketing Channels for Events
Bots as Marketing Channels for EventsBots as Marketing Channels for Events
Bots as Marketing Channels for Events
 
The art of building successful products
The art of building successful productsThe art of building successful products
The art of building successful products
 
Basics of Product Strategy
Basics of Product StrategyBasics of Product Strategy
Basics of Product Strategy
 
Vue.js SSR with Nuxt.js and Firebase
Vue.js SSR with Nuxt.js and Firebase Vue.js SSR with Nuxt.js and Firebase
Vue.js SSR with Nuxt.js and Firebase
 
Work at oratio - Tools for distributed teams
Work at oratio - Tools for distributed teamsWork at oratio - Tools for distributed teams
Work at oratio - Tools for distributed teams
 
How to build a great bot
How to build a great botHow to build a great bot
How to build a great bot
 
Chatbots - Canonical Interfaces as new Communication Channels
Chatbots - Canonical Interfaces as new Communication ChannelsChatbots - Canonical Interfaces as new Communication Channels
Chatbots - Canonical Interfaces as new Communication Channels
 

Dernier

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 

Dernier (20)

Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 

ReactiveMongo - non blocking and asynchronous I/O operations

  • 1. reactivemongo by david pichsenmeister
  • 2. overview ● fully non-blocking ● asynchronous I/O operations ● build against Akka 2.2 & 2.3 ● build against Scala 2.10 & 2.11
  • 3. play! 2.3 plugin ● support to play! 2.3 ● JSON <-> BSON conversion with embedded JSON library in play! ● JSONCollection instead of ReactiveMongo’s BSONDocument
  • 4. case class Pokemon( _id: BSONObjectID, name: String, category: String, moves: List[String] ) object Pokemon { implicit val pokemonFormat: Format[Pokemon] = Json.format[Pokemon] }
  • 5. object PokemonDAO { private def collectionName: String = "pokemon" private def db = ReactiveMongoPlugin.db private def collection = db[JSONCollection](collectionName)
  • 6. def insert(pokemon: Pokemon): Future[LastError] = { collection.insert(Json.toJson(pokemon)) } def update(pokemon: Pokemon): Future[LastError] = { collection.update(BSONDocument("_id" -> pokemon._id), Json.toJson(pokemon)) } def remove(pokemon: Pokemon): Future[LastError] = { collection.remove(BSONDocument("_id" -> pokemon._id)) }
  • 7. def findById(id: BSONObjectID): Future[Option[Pokemon] = { collection.find(BSONDocument("_id" -> id)).cursor[Pokemon].headOption } def findByCategory(cat: String): Future[List[Pokemon] = { collection.find(BSONDocument("category" -> cat)).options(QueryOpts(skipN = 0, batchSizeN = 10)).cursor[Pokemon].collect[List]() } def catchEmAll(): Future[List[Pokemon] = { collection.find(BSONDocument()). cursor[Pokemon].collect[List]() }
  • 8. def update() = Action.async(parse.json) { // DON’T do this at home, kids!! val pokemon = Json.fromJson[Pokemon](request.body).get val future: Future =PokemonDAO.update(pokemon) future.map(lastError => { Accepted }) } controller
  • 9. more features ● GridFS as non-blocking, streaming datastore ● Enumerator/Iteratee pattern to avoid huge memory usage
  • 10. val cursor = collection.find(BSONDocument()).cursor[Pokemon] cursor.enumerate().apply(Iteratee.foreach { pokemon => println("found pokemon: " + pokemon.name) }) enumerator/iteratee
  • 12. thanks! feel free to add me on: .../3x14159265