The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js

MongoDB
MongoDBMarketing Ninja at MongoDB
A Guide to the MEAN Stack
Tips and Tricks for using MongoDB and NodeJS
in overwhelmingly awesome ways
Valeri Karpov
CTO, Ascot Project
www.thecodebarbarian.com
@code_barbarian
github.com/vkarpov15
What is The Ascot Project?
Making fashion geek-friendly
Less like this More like this
Who is this guy?
- Academy for Telecommunications and
Computer Science '07, Princeton CS '11
- Co-founder and CTO, SCVNGR in '08
- Google intern '09, mentored by Misko
Hevery
- Tower Research Capital '11 – '13
- Developed Ascot Project at AngelHack
DC in '12
What is this all about?
- Why Ascot uses MongoDB
- What's the MEAN stack and why its awesome
- How MongoDB fits in the MEAN stack
- Why MongooseJS is important and tradeoffs in it's usage
- Example of a cool MEAN stack web app
Why MongoDB?
1) It's cool
2) No joins for nested data
3) Flexible and simple
SQL is Annoying
MEAN Stack
Web dev framework for NodeJS
Superheroic frontend framework
Event-based concurrency environment
MEAN Stack – Why do I care?
- Write one language
- With MongoDB and Mongoose, easy and flexible data
validation
- With NodeJS, never need threads
- With AngularJS, dynamic client-side templates
Same Language, Same Objects
{ "_id" : ObjectId("5161a58b46341f8a46000003"),
"username" : "vkarpov" }
{ "_id" : "5161a58b46341f8a46000003",
"username" : "vkarpov" }
{ "_id" : "5161a58b46341f8a46000003",
"username" : "vkarpov" }
How MongooseJS Works
MongooseJS – code-defined schemas for MongoDB + NodeJS
- MongoDB and NodeJS are best friends
- No built-in schemas or validation
- But, MongoDB native wrapper for NodeJS is lacking:
How MongooseJS Works
MongooseJS – code-defined schemas for MongoDB + NodeJS
Primary MongooseJS types:
- Schema – structure defining how documents look
- Connection – Wrapper around database connection
- Model = Schema + Connection + collection name
- Document is an instantiation of a Model
How MongooseJS Works
A Basic MongooseJS Schema
How MongooseJS Works
Using the StockPrice Model
How MongooseJS Works
Sometimes being able to save anything isn't right
How MongooseJS Works
Helpful Error Messages
- Nested JSON errors
summary
- Can use this for very
generic form validation
- More on this later
How MongooseJS Works
Nesting and populating MongooseJS Schemas – an important
distinction that doesn't exist in SQL
Populate – similar to SQL join
Nest – re-use schema in another
schema
How MongooseJS Works
Can't do multi-level population!
How MongooseJS Works
Nesting and populating MongooseJS Schemas
When can we use nested schemas?
Many-to-one
One-to-many
One-to-one
Many-to-many
MEAN Stack Superpowers
NodeJS is not just a Javascript web server
- Event based concurrency
- Package manager similar to Rails gems
- Makes multithreaded servers easy
Example: Bitcoins!
Bitcoin P&L
Step 1 : Web app to display a streaming Bitcoin ticker
- Complex problem – multiple threads, sockets, mutex, etc.
- People in HFT get paid crazy money to do this in C++
Bitcoin P&L
- Enter NodeJS, where this is a back-of-napkin type problem
Bitcoin P&L
- Update frontend periodically? AngularJS makes it easy
Bitcoin P&L
Takeaways
- General problem : your server connecting to other servers
- Example : Ascot links
- Can write multi-threaded servers, but why?
- General problem : updating page without reload
- AngularJS two-way data binding
Bitcoin P&L + MongoDB
Model – list of nested stock schemas Routes – get list of stocks, add a new stock
Bitcoin P&L + MongoDB
AngularJS – generic no-reload form wrapper
Bitcoin P&L + MongoDB
Jade – A View To A Kill And the result:
Takeaways
- MEAN Stack is awesome
- Sophisticated frontends
- Multithreaded backends made easy
- MongooseJS helps NodeJS and MongoDB play nice
- Limitations on MongooseJS population
Thanks for Listening!
Further Reading
- Ascot Project : www.ascotproject.com
- AngularJS Form Validation : “How to Easily Validate Any Form
Ever Using AngularJS” @ www.thecodebarbarian.com
- SocketIO Bitcoin Price Streaming : mtgox-socket-client on NPM
and Github
- Bitcoin realtime P&L : github.com/vkarpov15/bitcoin-pnl,
coming soon to www.thecodebarbarian.com
1 of 29

Recommended

Introduction to MongoDB by
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRavi Teja
53.5K views20 slides
MongoDB Fundamentals by
MongoDB FundamentalsMongoDB Fundamentals
MongoDB FundamentalsMongoDB
1.8K views46 slides
Web Services PHP Tutorial by
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP TutorialLorna Mitchell
192.2K views78 slides
Exploring the power of Gradle in android studio - Basics & Beyond by
Exploring the power of Gradle in android studio - Basics & BeyondExploring the power of Gradle in android studio - Basics & Beyond
Exploring the power of Gradle in android studio - Basics & BeyondKaushal Dhruw
1.4K views62 slides
Expressjs by
ExpressjsExpressjs
ExpressjsYauheni Nikanovich
608 views17 slides
Express js by
Express jsExpress js
Express jsManav Prasad
6.7K views19 slides

More Related Content

What's hot

Pentesting RESTful webservices by
Pentesting RESTful webservicesPentesting RESTful webservices
Pentesting RESTful webservicesMohammed A. Imran
20.2K views65 slides
Node js Introduction by
Node js IntroductionNode js Introduction
Node js Introductionsanskriti agarwal
365 views8 slides
An introduction to MongoDB by
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDBUniversidade de São Paulo
1.7K views69 slides
Documenting your REST API with Swagger - JOIN 2014 by
Documenting your REST API with Swagger - JOIN 2014Documenting your REST API with Swagger - JOIN 2014
Documenting your REST API with Swagger - JOIN 2014JWORKS powered by Ordina
830 views22 slides
Introduction to mongodb by
Introduction to mongodbIntroduction to mongodb
Introduction to mongodbneela madheswari
559 views64 slides
MongoDB by
MongoDBMongoDB
MongoDBnikhil2807
8.6K views31 slides

What's hot(20)

Introduction to Swagger by Knoldus Inc.
Introduction to SwaggerIntroduction to Swagger
Introduction to Swagger
Knoldus Inc.5.9K views
Spring Data JDBC: Beyond the Obvious by VMware Tanzu
Spring Data JDBC: Beyond the ObviousSpring Data JDBC: Beyond the Obvious
Spring Data JDBC: Beyond the Obvious
VMware Tanzu818 views
When to Use MongoDB by MongoDB
When to Use MongoDBWhen to Use MongoDB
When to Use MongoDB
MongoDB22.3K views
Mongodb basics and architecture by Bishal Khanal
Mongodb basics and architectureMongodb basics and architecture
Mongodb basics and architecture
Bishal Khanal2.1K views
Understanding REST APIs in 5 Simple Steps by Tessa Mero
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple Steps
Tessa Mero5K views
Salesforce Internship Presentation (Summer 2012) by Nitin Jain
Salesforce Internship Presentation (Summer 2012)Salesforce Internship Presentation (Summer 2012)
Salesforce Internship Presentation (Summer 2012)
Nitin Jain2.5K views
Overview of React.JS - Internship Presentation - Week 5 by Devang Garach
Overview of React.JS - Internship Presentation - Week 5Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5
Devang Garach1.8K views

Viewers also liked

Introduction to the MEAN stack by
Introduction to the MEAN stackIntroduction to the MEAN stack
Introduction to the MEAN stackYoann Gotthilf
4.2K views10 slides
Does my DIV look big in this? by
Does my DIV look big in this?Does my DIV look big in this?
Does my DIV look big in this?glen_a_smith
1.5K views68 slides
Single Page Application presentation by
Single Page Application presentationSingle Page Application presentation
Single Page Application presentationJohn Staveley
2.1K views22 slides
Single Page Application (SPA) using AngularJS by
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSM R Rony
29.8K views19 slides
Single Page Applications by
Single Page ApplicationsSingle Page Applications
Single Page ApplicationsMassimo Iacolare
4.4K views40 slides
Building single page applications by
Building single page applicationsBuilding single page applications
Building single page applicationsSC5.io
7K views22 slides

Viewers also liked(14)

Introduction to the MEAN stack by Yoann Gotthilf
Introduction to the MEAN stackIntroduction to the MEAN stack
Introduction to the MEAN stack
Yoann Gotthilf4.2K views
Does my DIV look big in this? by glen_a_smith
Does my DIV look big in this?Does my DIV look big in this?
Does my DIV look big in this?
glen_a_smith1.5K views
Single Page Application presentation by John Staveley
Single Page Application presentationSingle Page Application presentation
Single Page Application presentation
John Staveley2.1K views
Single Page Application (SPA) using AngularJS by M R Rony
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJS
M R Rony29.8K views
Building single page applications by SC5.io
Building single page applicationsBuilding single page applications
Building single page applications
SC5.io7K views
Get MEAN! Node.js and the MEAN stack by Nicholas McClay
Get MEAN!  Node.js and the MEAN stackGet MEAN!  Node.js and the MEAN stack
Get MEAN! Node.js and the MEAN stack
Nicholas McClay18.5K views
Introduction To Single Page Application by KMS Technology
Introduction To Single Page ApplicationIntroduction To Single Page Application
Introduction To Single Page Application
KMS Technology10.8K views
AngularJS 101 - Everything you need to know to get started by Stéphane Bégaudeau
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
Stéphane Bégaudeau55.5K views
AngularJS application architecture by Gabriele Falace
AngularJS application architectureAngularJS application architecture
AngularJS application architecture
Gabriele Falace12.7K views
AngularJS Architecture by Eyal Vardi
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Eyal Vardi64.9K views
Introduction to Angular 2 by Knoldus Inc.
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
Knoldus Inc.22.4K views

Similar to The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js

MEAN Stack - Google Developers Live 10/03/2013 by
MEAN Stack - Google Developers Live 10/03/2013MEAN Stack - Google Developers Live 10/03/2013
MEAN Stack - Google Developers Live 10/03/2013Valeri Karpov
4.3K views16 slides
Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and... by
Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...
Open-Source Analytics Stack on MongoDB, with Schema, Pierre-Alain Jachiet and...Pôle Systematic Paris-Region
2.3K views57 slides
Create Restful Web Application With Node.js Express Framework by
Create Restful Web Application With Node.js Express FrameworkCreate Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express FrameworkEdureka!
3.2K views16 slides
LAMP is so yesterday, MEAN is so tomorrow! :) by
LAMP is so yesterday, MEAN is so tomorrow! :) LAMP is so yesterday, MEAN is so tomorrow! :)
LAMP is so yesterday, MEAN is so tomorrow! :) Sascha Sambale
9.8K views70 slides
Introduction to MongoDB by
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBJean-Luc David
852 views20 slides
NodeSummit - MEAN Stack by
NodeSummit - MEAN StackNodeSummit - MEAN Stack
NodeSummit - MEAN StackValeri Karpov
4.1K views32 slides

Similar to The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js(20)

MEAN Stack - Google Developers Live 10/03/2013 by Valeri Karpov
MEAN Stack - Google Developers Live 10/03/2013MEAN Stack - Google Developers Live 10/03/2013
MEAN Stack - Google Developers Live 10/03/2013
Valeri Karpov4.3K views
Create Restful Web Application With Node.js Express Framework by Edureka!
Create Restful Web Application With Node.js Express FrameworkCreate Restful Web Application With Node.js Express Framework
Create Restful Web Application With Node.js Express Framework
Edureka!3.2K views
LAMP is so yesterday, MEAN is so tomorrow! :) by Sascha Sambale
LAMP is so yesterday, MEAN is so tomorrow! :) LAMP is so yesterday, MEAN is so tomorrow! :)
LAMP is so yesterday, MEAN is so tomorrow! :)
Sascha Sambale9.8K views
NodeSummit - MEAN Stack by Valeri Karpov
NodeSummit - MEAN StackNodeSummit - MEAN Stack
NodeSummit - MEAN Stack
Valeri Karpov4.1K views
Backend Development Bootcamp - Node [Online & Offline] In Bangla by Stack Learner
Backend Development Bootcamp - Node [Online & Offline] In BanglaBackend Development Bootcamp - Node [Online & Offline] In Bangla
Backend Development Bootcamp - Node [Online & Offline] In Bangla
Stack Learner173 views
Beginning MEAN Stack by Rob Davarnia
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
Rob Davarnia1.5K views
MongoDB and the MEAN Stack by MongoDB
MongoDB and the MEAN StackMongoDB and the MEAN Stack
MongoDB and the MEAN Stack
MongoDB11.1K views
NoSQL and MongoDB Introdction by Brian Enochson
NoSQL and MongoDB IntrodctionNoSQL and MongoDB Introdction
NoSQL and MongoDB Introdction
Brian Enochson5.3K views
AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja... by Bojan Veljanovski
AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...
AngularJS + NancyFx + MongoDB = The best trio for ultimate SPA by Bojan Velja...
Bojan Veljanovski8.5K views
Beyond the MEAN Stack: Thinking Small with Node.js for the Enterprise by Forrest Norvell
Beyond the MEAN Stack: Thinking Small with Node.js for the EnterpriseBeyond the MEAN Stack: Thinking Small with Node.js for the Enterprise
Beyond the MEAN Stack: Thinking Small with Node.js for the Enterprise
Forrest Norvell9.6K views
Building an E-commerce website in MEAN stack by divyapisces
Building an E-commerce website in MEAN stackBuilding an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stack
divyapisces8.1K views
Node PDX: Intro to Sails.js by Mike McNeil
Node PDX: Intro to Sails.jsNode PDX: Intro to Sails.js
Node PDX: Intro to Sails.js
Mike McNeil6.9K views
Node.js and MongoDB from scratch, fully explained and tested by John Culviner
Node.js and MongoDB from scratch, fully explained and tested Node.js and MongoDB from scratch, fully explained and tested
Node.js and MongoDB from scratch, fully explained and tested
John Culviner1.3K views
Developing and Testing a MongoDB and Node.js REST API by All Things Open
Developing and Testing a MongoDB and Node.js REST APIDeveloping and Testing a MongoDB and Node.js REST API
Developing and Testing a MongoDB and Node.js REST API
All Things Open2.8K views

More from MongoDB

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas by
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB
6.7K views46 slides
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts! by
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB
1.2K views20 slides
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel... by
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB
1.1K views40 slides
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB by
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB
1.4K views106 slides
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T... by
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB
782 views37 slides
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data by
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB
870 views47 slides

More from MongoDB(20)

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas by MongoDB
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB6.7K views
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts! by MongoDB
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB1.2K views
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel... by MongoDB
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB1.1K views
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB by MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB1.4K views
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T... by MongoDB
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB782 views
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data by MongoDB
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB870 views
MongoDB SoCal 2020: MongoDB Atlas Jump Start by MongoDB
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB633 views
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys] by MongoDB
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB528 views
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2 by MongoDB
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB473 views
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ... by MongoDB
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB492 views
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts! by MongoDB
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB355 views
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset by MongoDB
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB383 views
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart by MongoDB
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB287 views
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin... by MongoDB
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB392 views
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++ by MongoDB
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB359 views
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo... by MongoDB
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB382 views
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive by MongoDB
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB330 views
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang by MongoDB
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB293 views
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app... by MongoDB
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB328 views
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning... by MongoDB
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB312 views

Recently uploaded

"Running students' code in isolation. The hard way", Yurii Holiuk by
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk Fwdays
24 views34 slides
Democratising digital commerce in India-Report by
Democratising digital commerce in India-ReportDemocratising digital commerce in India-Report
Democratising digital commerce in India-ReportKapil Khandelwal (KK)
20 views161 slides
Data Integrity for Banking and Financial Services by
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial ServicesPrecisely
29 views26 slides
STPI OctaNE CoE Brochure.pdf by
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdfmadhurjyapb
14 views1 slide
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc
72 views29 slides
Microsoft Power Platform.pptx by
Microsoft Power Platform.pptxMicrosoft Power Platform.pptx
Microsoft Power Platform.pptxUni Systems S.M.S.A.
61 views38 slides

Recently uploaded(20)

"Running students' code in isolation. The hard way", Yurii Holiuk by Fwdays
"Running students' code in isolation. The hard way", Yurii Holiuk "Running students' code in isolation. The hard way", Yurii Holiuk
"Running students' code in isolation. The hard way", Yurii Holiuk
Fwdays24 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely29 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc72 views
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe by Simone Puorto
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
2024: A Travel Odyssey The Role of Generative AI in the Tourism Universe
Simone Puorto13 views
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson126 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...

The MEAN Stack: MongoDB, ExpressJS, AngularJS and Node.js

  • 1. A Guide to the MEAN Stack Tips and Tricks for using MongoDB and NodeJS in overwhelmingly awesome ways Valeri Karpov CTO, Ascot Project www.thecodebarbarian.com @code_barbarian github.com/vkarpov15
  • 2. What is The Ascot Project? Making fashion geek-friendly Less like this More like this
  • 3. Who is this guy? - Academy for Telecommunications and Computer Science '07, Princeton CS '11 - Co-founder and CTO, SCVNGR in '08 - Google intern '09, mentored by Misko Hevery - Tower Research Capital '11 – '13 - Developed Ascot Project at AngelHack DC in '12
  • 4. What is this all about? - Why Ascot uses MongoDB - What's the MEAN stack and why its awesome - How MongoDB fits in the MEAN stack - Why MongooseJS is important and tradeoffs in it's usage - Example of a cool MEAN stack web app
  • 5. Why MongoDB? 1) It's cool 2) No joins for nested data 3) Flexible and simple
  • 7. MEAN Stack Web dev framework for NodeJS Superheroic frontend framework Event-based concurrency environment
  • 8. MEAN Stack – Why do I care? - Write one language - With MongoDB and Mongoose, easy and flexible data validation - With NodeJS, never need threads - With AngularJS, dynamic client-side templates
  • 9. Same Language, Same Objects { "_id" : ObjectId("5161a58b46341f8a46000003"), "username" : "vkarpov" } { "_id" : "5161a58b46341f8a46000003", "username" : "vkarpov" } { "_id" : "5161a58b46341f8a46000003", "username" : "vkarpov" }
  • 10. How MongooseJS Works MongooseJS – code-defined schemas for MongoDB + NodeJS - MongoDB and NodeJS are best friends - No built-in schemas or validation - But, MongoDB native wrapper for NodeJS is lacking:
  • 11. How MongooseJS Works MongooseJS – code-defined schemas for MongoDB + NodeJS Primary MongooseJS types: - Schema – structure defining how documents look - Connection – Wrapper around database connection - Model = Schema + Connection + collection name - Document is an instantiation of a Model
  • 12. How MongooseJS Works A Basic MongooseJS Schema
  • 13. How MongooseJS Works Using the StockPrice Model
  • 14. How MongooseJS Works Sometimes being able to save anything isn't right
  • 15. How MongooseJS Works Helpful Error Messages - Nested JSON errors summary - Can use this for very generic form validation - More on this later
  • 16. How MongooseJS Works Nesting and populating MongooseJS Schemas – an important distinction that doesn't exist in SQL Populate – similar to SQL join Nest – re-use schema in another schema
  • 17. How MongooseJS Works Can't do multi-level population!
  • 18. How MongooseJS Works Nesting and populating MongooseJS Schemas When can we use nested schemas? Many-to-one One-to-many One-to-one Many-to-many
  • 19. MEAN Stack Superpowers NodeJS is not just a Javascript web server - Event based concurrency - Package manager similar to Rails gems - Makes multithreaded servers easy
  • 21. Bitcoin P&L Step 1 : Web app to display a streaming Bitcoin ticker - Complex problem – multiple threads, sockets, mutex, etc. - People in HFT get paid crazy money to do this in C++
  • 22. Bitcoin P&L - Enter NodeJS, where this is a back-of-napkin type problem
  • 23. Bitcoin P&L - Update frontend periodically? AngularJS makes it easy
  • 24. Bitcoin P&L Takeaways - General problem : your server connecting to other servers - Example : Ascot links - Can write multi-threaded servers, but why? - General problem : updating page without reload - AngularJS two-way data binding
  • 25. Bitcoin P&L + MongoDB Model – list of nested stock schemas Routes – get list of stocks, add a new stock
  • 26. Bitcoin P&L + MongoDB AngularJS – generic no-reload form wrapper
  • 27. Bitcoin P&L + MongoDB Jade – A View To A Kill And the result:
  • 28. Takeaways - MEAN Stack is awesome - Sophisticated frontends - Multithreaded backends made easy - MongooseJS helps NodeJS and MongoDB play nice - Limitations on MongooseJS population
  • 29. Thanks for Listening! Further Reading - Ascot Project : www.ascotproject.com - AngularJS Form Validation : “How to Easily Validate Any Form Ever Using AngularJS” @ www.thecodebarbarian.com - SocketIO Bitcoin Price Streaming : mtgox-socket-client on NPM and Github - Bitcoin realtime P&L : github.com/vkarpov15/bitcoin-pnl, coming soon to www.thecodebarbarian.com