SlideShare a Scribd company logo
Lessons in Open Source from the
MongooseJS ODM
Valeri Karpov
Software Engineer, MongoDB
www.thecodebarbarian.com
www.slideshare.net/vkarpov15
github.com/vkarpov15
@code_barbarian
*
Who Am I?
•NodeJS Engineer at MongoDB
•Maintainer of mongoose ODM
•Former CTO, LevelUp
•Hacker in Residence at BookaLokal
•Author of Professional AngularJS
*
Talk Overview
•How I got into mongoose
•High-level overview of how mongoose works
•Recent new features
•What I’m working on now
•Lessons learned from my first year
*
What is Mongoose?
•MongoDB ODM for NodeJS
•Schema validation for schema-less database
•Neat syntax for building MongoDB operations
•Very active module:
• 400k downloads/month
• 7000 GitHub stars
• 5-20 GitHub issue notifications/day
*
How I got into Mongoose
•Aug 2012: work with janky C++ event loop in HFT
•Nov 2012: start working on fashion startup
•Dec 2012: discover mongoose, cut SLOC in half
•Jan 2013: Leave HFT shop
•Apr 2013: Write original MEAN stack blog post
•Aug 2013: Leave startup land and go to MongoDB
*
How I got into Mongoose
•Dec 2013: Aaron Heckmann leaves MongoDB
•Apr 2014: Handoff over Twitter
*
How does Mongoose Work?
•Core features:
• Schema validation
• Syntactic sugar for persisting documents
• Hooks
*
Part 1: Mongoose Schema Validation
•MongoDB is schema-less...
•But you don’t want end users to store arbitrary data
*
Mongoose Schema Validation
*
Part 2: Syntactic Sugar for Updates
•MongoDB updates look like this:
•
•Do I have to manually build the update part?
*
Object.defineProperty()
•Current JavaScript spec lets you hook into property
access
*
Syntactic Sugar for Updates
•General idea: define mongoose schema
● When creating doc, loop over all schema paths
● For each path, use Object.defineProperty()
● Object.defineProperty() setter converts:
● Into:
● save() applies all updates
*
Part 3: Hooks / middleware
•Schema-level business logic
•Suppose you want to:
• Add a timestamp every time you save()
• Add your own caching layer to queries
• Log every query based on config file setting
*
Hooks / middleware
•Schema-level business logic
*
Hooks => Plugins
•Higher-level concept of “plugins”
•External hooks
*
Recent Additions
•Mongoose 4.0 released March 25
•Sweet new features:
• Query middleware
• Schema validation in the browser
• Validators on update()
*
What I’m Working On Now
•Promises: OOP for async operations
•Single biggest source of mongoose feature requests
*
Promises Explained
•General idea: users don’t like nested callbacks
•See Callback Hell is a Myth
*
Promises Explained
•Promises provide flatter structure
*
This Sounds Great But...
•The promises space is wildly fragmented
•Ask 10 users, get 10 different favorite promises
libraries - Bluebird, Q, RSVP, When, native ES6
•Mongoose promises feature requests are usually
• Use promises library X natively
• Support promises library Y’s feature Z
*
General Solution
•Mongoose 4 uses mpromise natively
•mpromise designed for ease rather than features or
performance, minimal adoption outside of mongoose
•Considering deprecating native promise support
•For now, planned solution is to allow users to specify
promise library of choice
*
Challenges
•Hooks and promises are confusing
•Promises need to be resolved
•Should they be resolved before or after post hooks?
•If after, hooks library needs to handle resolving!
*
Final Bit: Lessons Learned
•Linus’ Law:
•“Given a large enough beta-tester and co-developer
base, almost every problem will be characterized
quickly and the fix will be obvious to someone”
•Open source code is great because of the combined
input of the entire user base
*
Final Bit: Lessons Learned
•When using mongoose, you get contributions from a
lot of smart people
● The value of an OS module is (usually) proportional
to its user base
*
Final Bit: Lessons Learned
•Putting your code in the open makes you go the extra
mile to make it awesome
•And sometimes you have to eat some humble pie
*
First Rule in Running an Open Source
Module
•Always be responsive
•Nothing is worse than opening a github issue and not
having anybody touch it for a month
•Worse: somebody responds and says this library is no
longer maintained
*
Second Rule: Lead with a Clear
Vision
•Not necessarily in conflict with the “get people
involved”
•Easy for a module to become bloated
•One-off contributors aren’t as invested in the module
•Leads to unclear interfaces
•For instance, yeoman Ionic generator
*
ABD: Always Be Dogfooding
•Why I work on BookaLokal, mongoose plugins, etc.
•“Nobody should start to undertake a large project. You
start with a small trivial project, and you should never
expect it to get large... If it doesn't solve some fairly
immediate need, it's almost certainly over-designed... You
need to get something half-way useful first, and then
others will say "hey, that almost works for me", and they'll
get involved in the project.” - Linus Torvalds
*
Thanks for Listening!
•Slides on:
• Twitter: @code_barbarian
• Slideshare: slideshare.net/vkarpov15
•Mongoose on Github

More Related Content

What's hot (19)

PDF
MEAN Stack - Google Developers Live 10/03/2013
Valeri Karpov
 
PDF
JSFoo-2017 Takeaways
Mir Ali
 
PPTX
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
Irfan Maulana
 
PPTX
External JavaScript Widget Development Best Practices (updated) (v.1.1)
Volkan Özçelik
 
PPTX
External JavaScript Widget Development Best Practices
Volkan Özçelik
 
PPTX
Java scriptwidgetdevelopmentjstanbul2012
Volkan Özçelik
 
PPT
Next generation frontend tooling
pksjce
 
PPTX
PHP Indonesia - Nodejs Web Development
Irfan Maulana
 
PDF
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
Valeri Karpov
 
PDF
Node js projects
💾 Radek Fabisiak
 
PDF
The Dark Side of Single Page Applications
Dor Kalev
 
PPTX
Presentation
Nikhilesh Sharma
 
PDF
Afrimadoni the power of docker
PHP Indonesia
 
PDF
The MEAN Stack
Md. Ziaul Haq
 
PDF
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...
Corey Clark, Ph.D.
 
PDF
Testing Mobile JavaScript (Fall 2010
jeresig
 
PPTX
MEAN Stack
RoshanTak1
 
PDF
Bringing The Sexy Back To WebWorkers
Corey Clark, Ph.D.
 
PPTX
Introduction to NodeJS
Zahid Mahir
 
MEAN Stack - Google Developers Live 10/03/2013
Valeri Karpov
 
JSFoo-2017 Takeaways
Mir Ali
 
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
Irfan Maulana
 
External JavaScript Widget Development Best Practices (updated) (v.1.1)
Volkan Özçelik
 
External JavaScript Widget Development Best Practices
Volkan Özçelik
 
Java scriptwidgetdevelopmentjstanbul2012
Volkan Özçelik
 
Next generation frontend tooling
pksjce
 
PHP Indonesia - Nodejs Web Development
Irfan Maulana
 
MEAN Stack NYC Meetup 20150717: TDD Your AngularJS + Ionic Directives With jQ...
Valeri Karpov
 
Node js projects
💾 Radek Fabisiak
 
The Dark Side of Single Page Applications
Dor Kalev
 
Presentation
Nikhilesh Sharma
 
Afrimadoni the power of docker
PHP Indonesia
 
The MEAN Stack
Md. Ziaul Haq
 
Building a Multithreaded Web-Based Game Engine Using HTML5/CSS3 and JavaScrip...
Corey Clark, Ph.D.
 
Testing Mobile JavaScript (Fall 2010
jeresig
 
MEAN Stack
RoshanTak1
 
Bringing The Sexy Back To WebWorkers
Corey Clark, Ph.D.
 
Introduction to NodeJS
Zahid Mahir
 

Viewers also liked (17)

PDF
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
Valeri Karpov
 
PDF
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
Valeri Karpov
 
PDF
MongoDB Israel June Meetup
Valeri Karpov
 
PDF
Mongo db in 3 minutes BoilerMake
Valeri Karpov
 
PDF
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous Integration
Valeri Karpov
 
PDF
JS-IL: Getting MEAN in 1 Hour
Valeri Karpov
 
PPS
Kobietazmelodia
vikas_deshpande
 
PPT
Media presentation of draupadi's choice
Harry Whitley
 
PPT
Winning strategy -learnt from Mahabarat
vikas_deshpande
 
PDF
MongoDB: Queries and Aggregation Framework with NBA Game Data
Valeri Karpov
 
PPTX
Mahabharat and geeta
K RAMESH, KENDRIYA VIDYALAYA SANGATHAN
 
PDF
NodeSummit - MEAN Stack
Valeri Karpov
 
PDF
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Valeri Karpov
 
PPTX
MAHABHARATA
M QASIF MASIS
 
PPTX
Mahabharata Summary
Marc Respecia
 
PDF
Summary of the Mahabharata of Vyasa
Jasodra Rampersad
 
PPT
Bhagavad Gita and Management
arthi_shankar
 
MongoDB Miami Meetup 1/26/15: Introduction to WiredTiger
Valeri Karpov
 
JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond
Valeri Karpov
 
MongoDB Israel June Meetup
Valeri Karpov
 
Mongo db in 3 minutes BoilerMake
Valeri Karpov
 
AngularJS Meetup 11/19/13 - AngularJS for MongoDB Continuous Integration
Valeri Karpov
 
JS-IL: Getting MEAN in 1 Hour
Valeri Karpov
 
Kobietazmelodia
vikas_deshpande
 
Media presentation of draupadi's choice
Harry Whitley
 
Winning strategy -learnt from Mahabarat
vikas_deshpande
 
MongoDB: Queries and Aggregation Framework with NBA Game Data
Valeri Karpov
 
NodeSummit - MEAN Stack
Valeri Karpov
 
Nimrod: MongoDB Shell in NodeJS (JSConfUY 2015)
Valeri Karpov
 
MAHABHARATA
M QASIF MASIS
 
Mahabharata Summary
Marc Respecia
 
Summary of the Mahabharata of Vyasa
Jasodra Rampersad
 
Bhagavad Gita and Management
arthi_shankar
 
Ad

Similar to Lessons in Open Source from the MongooseJS ODM (20)

PDF
MongoDB at Yle
MongoDB
 
PDF
Developing and Testing a MongoDB and Node.js REST API
All Things Open
 
PPTX
Mongo db tips and advance features
Sujith Sudhakaran
 
PPTX
Mongodb beijingconf yottaa_3.3
Yottaa
 
PDF
MongoDB and the MEAN Stack
MongoDB
 
PPTX
MongoDB World 2018: Tutorial - MongoDB & NodeJS: Zero to Hero in 80 Minutes
MongoDB
 
PDF
Lessons from 4 years of driver develoment
christkv
 
PPTX
Enhanced CRUD Operations with Mongoose in Node.js
murasolimathavi
 
PDF
Lessons learned from a large scale OSGii web app - P Bakker & J de Vreede
mfrancis
 
PDF
Javascript Web Applications Otx Alex Maccaw
fahradzereit93
 
KEY
Mongo and node mongo dc 2011
async_io
 
PPTX
Webinar: Get Started with the MEAN Stack
MongoDB
 
PPTX
Node js crash course session 5
Abdul Rahman Masri Attal
 
PPT
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
MongoDB
 
PDF
node.js, javascript and the future
Jeff Miccolis
 
PPTX
Intro to node and mongodb 1
Mohammad Qureshi
 
PDF
Backend Basic in nodejs express and mongodb PPT.pdf
sadityaraj353
 
PDF
Mongodb
Thiago Veiga
 
PDF
Introduction to REST API with Node.js
Yoann Gotthilf
 
PDF
Mongoose: MongoDB object modelling for Node.js
Yuriy Bogomolov
 
MongoDB at Yle
MongoDB
 
Developing and Testing a MongoDB and Node.js REST API
All Things Open
 
Mongo db tips and advance features
Sujith Sudhakaran
 
Mongodb beijingconf yottaa_3.3
Yottaa
 
MongoDB and the MEAN Stack
MongoDB
 
MongoDB World 2018: Tutorial - MongoDB & NodeJS: Zero to Hero in 80 Minutes
MongoDB
 
Lessons from 4 years of driver develoment
christkv
 
Enhanced CRUD Operations with Mongoose in Node.js
murasolimathavi
 
Lessons learned from a large scale OSGii web app - P Bakker & J de Vreede
mfrancis
 
Javascript Web Applications Otx Alex Maccaw
fahradzereit93
 
Mongo and node mongo dc 2011
async_io
 
Webinar: Get Started with the MEAN Stack
MongoDB
 
Node js crash course session 5
Abdul Rahman Masri Attal
 
The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js
MongoDB
 
node.js, javascript and the future
Jeff Miccolis
 
Intro to node and mongodb 1
Mohammad Qureshi
 
Backend Basic in nodejs express and mongodb PPT.pdf
sadityaraj353
 
Mongodb
Thiago Veiga
 
Introduction to REST API with Node.js
Yoann Gotthilf
 
Mongoose: MongoDB object modelling for Node.js
Yuriy Bogomolov
 
Ad

More from Valeri Karpov (8)

PDF
A Practical Introduction to GeoJSON
Valeri Karpov
 
PDF
A Practical Introduction to Functions-as-a-Service
Valeri Karpov
 
PDF
A Gentle Introduction to Functions-as-a-Service
Valeri Karpov
 
PDF
Introducing Async/Await
Valeri Karpov
 
PDF
TAO and the Essence of Modern JavaScript
Valeri Karpov
 
PDF
Mastering Async/Await in JavaScript
Valeri Karpov
 
PDF
React, Redux, and Archetype
Valeri Karpov
 
PDF
MongoDB API Talk @ HackPrinceton
Valeri Karpov
 
A Practical Introduction to GeoJSON
Valeri Karpov
 
A Practical Introduction to Functions-as-a-Service
Valeri Karpov
 
A Gentle Introduction to Functions-as-a-Service
Valeri Karpov
 
Introducing Async/Await
Valeri Karpov
 
TAO and the Essence of Modern JavaScript
Valeri Karpov
 
Mastering Async/Await in JavaScript
Valeri Karpov
 
React, Redux, and Archetype
Valeri Karpov
 
MongoDB API Talk @ HackPrinceton
Valeri Karpov
 

Recently uploaded (20)

PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
Next level data operations using Power Automate magic
Andries den Haan
 
PDF
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PDF
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PPTX
The birth and death of Stars - earth and life science
rizellemarieastrolo
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
PDF
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
Next level data operations using Power Automate magic
Andries den Haan
 
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
Bridging CAD, IBM TRIRIGA & GIS with FME: The Portland Public Schools Case
Safe Software
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
The birth and death of Stars - earth and life science
rizellemarieastrolo
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
99 Bottles of Trust on the Wall — Operational Principles for Trust in Cyber C...
treyka
 

Lessons in Open Source from the MongooseJS ODM

  • 1. Lessons in Open Source from the MongooseJS ODM Valeri Karpov Software Engineer, MongoDB www.thecodebarbarian.com www.slideshare.net/vkarpov15 github.com/vkarpov15 @code_barbarian
  • 2. * Who Am I? •NodeJS Engineer at MongoDB •Maintainer of mongoose ODM •Former CTO, LevelUp •Hacker in Residence at BookaLokal •Author of Professional AngularJS
  • 3. * Talk Overview •How I got into mongoose •High-level overview of how mongoose works •Recent new features •What I’m working on now •Lessons learned from my first year
  • 4. * What is Mongoose? •MongoDB ODM for NodeJS •Schema validation for schema-less database •Neat syntax for building MongoDB operations •Very active module: • 400k downloads/month • 7000 GitHub stars • 5-20 GitHub issue notifications/day
  • 5. * How I got into Mongoose •Aug 2012: work with janky C++ event loop in HFT •Nov 2012: start working on fashion startup •Dec 2012: discover mongoose, cut SLOC in half •Jan 2013: Leave HFT shop •Apr 2013: Write original MEAN stack blog post •Aug 2013: Leave startup land and go to MongoDB
  • 6. * How I got into Mongoose •Dec 2013: Aaron Heckmann leaves MongoDB •Apr 2014: Handoff over Twitter
  • 7. * How does Mongoose Work? •Core features: • Schema validation • Syntactic sugar for persisting documents • Hooks
  • 8. * Part 1: Mongoose Schema Validation •MongoDB is schema-less... •But you don’t want end users to store arbitrary data
  • 10. * Part 2: Syntactic Sugar for Updates •MongoDB updates look like this: • •Do I have to manually build the update part?
  • 11. * Object.defineProperty() •Current JavaScript spec lets you hook into property access
  • 12. * Syntactic Sugar for Updates •General idea: define mongoose schema ● When creating doc, loop over all schema paths ● For each path, use Object.defineProperty() ● Object.defineProperty() setter converts: ● Into: ● save() applies all updates
  • 13. * Part 3: Hooks / middleware •Schema-level business logic •Suppose you want to: • Add a timestamp every time you save() • Add your own caching layer to queries • Log every query based on config file setting
  • 15. * Hooks => Plugins •Higher-level concept of “plugins” •External hooks
  • 16. * Recent Additions •Mongoose 4.0 released March 25 •Sweet new features: • Query middleware • Schema validation in the browser • Validators on update()
  • 17. * What I’m Working On Now •Promises: OOP for async operations •Single biggest source of mongoose feature requests
  • 18. * Promises Explained •General idea: users don’t like nested callbacks •See Callback Hell is a Myth
  • 20. * This Sounds Great But... •The promises space is wildly fragmented •Ask 10 users, get 10 different favorite promises libraries - Bluebird, Q, RSVP, When, native ES6 •Mongoose promises feature requests are usually • Use promises library X natively • Support promises library Y’s feature Z
  • 21. * General Solution •Mongoose 4 uses mpromise natively •mpromise designed for ease rather than features or performance, minimal adoption outside of mongoose •Considering deprecating native promise support •For now, planned solution is to allow users to specify promise library of choice
  • 22. * Challenges •Hooks and promises are confusing •Promises need to be resolved •Should they be resolved before or after post hooks? •If after, hooks library needs to handle resolving!
  • 23. * Final Bit: Lessons Learned •Linus’ Law: •“Given a large enough beta-tester and co-developer base, almost every problem will be characterized quickly and the fix will be obvious to someone” •Open source code is great because of the combined input of the entire user base
  • 24. * Final Bit: Lessons Learned •When using mongoose, you get contributions from a lot of smart people ● The value of an OS module is (usually) proportional to its user base
  • 25. * Final Bit: Lessons Learned •Putting your code in the open makes you go the extra mile to make it awesome •And sometimes you have to eat some humble pie
  • 26. * First Rule in Running an Open Source Module •Always be responsive •Nothing is worse than opening a github issue and not having anybody touch it for a month •Worse: somebody responds and says this library is no longer maintained
  • 27. * Second Rule: Lead with a Clear Vision •Not necessarily in conflict with the “get people involved” •Easy for a module to become bloated •One-off contributors aren’t as invested in the module •Leads to unclear interfaces •For instance, yeoman Ionic generator
  • 28. * ABD: Always Be Dogfooding •Why I work on BookaLokal, mongoose plugins, etc. •“Nobody should start to undertake a large project. You start with a small trivial project, and you should never expect it to get large... If it doesn't solve some fairly immediate need, it's almost certainly over-designed... You need to get something half-way useful first, and then others will say "hey, that almost works for me", and they'll get involved in the project.” - Linus Torvalds
  • 29. * Thanks for Listening! •Slides on: • Twitter: @code_barbarian • Slideshare: slideshare.net/vkarpov15 •Mongoose on Github