A Guide to the MEAN StackTips and Tricks for using MongoDB and NodeJSin overwhelmingly awesome waysValeri KarpovCTO, Ascot...
What is The Ascot Project?Making fashion geek-friendlyLess like this More like this
Who is this guy?- Academy for Telecommunications andComputer Science 07, Princeton CS 11- Co-founder and CTO, SCVNGR in 08...
What is this all about?- Why Ascot uses MongoDB- Whats the MEAN stack and why its awesome- How MongoDB fits in the MEAN st...
Why MongoDB?1) Its cool2) No joins for nested data3) Flexible and simple
SQL is Annoying
MEAN StackWeb dev framework for NodeJSSuperheroic frontend frameworkEvent-based concurrency environment
MEAN Stack – Why do I care?- Write one language- With MongoDB and Mongoose, easy and flexible datavalidation- With NodeJS,...
Same Language, Same Objects{ "_id" : ObjectId("5161a58b46341f8a46000003"),"username" : "vkarpov" }{ "_id" : "5161a58b46341...
How MongooseJS WorksMongooseJS – code-defined schemas for MongoDB + NodeJS- MongoDB and NodeJS are best friends- No built-...
How MongooseJS WorksMongooseJS – code-defined schemas for MongoDB + NodeJSPrimary MongooseJS types:- Schema – structure de...
How MongooseJS WorksA Basic MongooseJS Schema
How MongooseJS WorksUsing the StockPrice Model
How MongooseJS WorksSometimes being able to save anything isnt right
How MongooseJS WorksHelpful Error Messages- Nested JSON errorssummary- Can use this for verygeneric form validation- More ...
How MongooseJS WorksNesting and populating MongooseJS Schemas – an importantdistinction that doesnt exist in SQLPopulate –...
How MongooseJS WorksCant do multi-level population!
How MongooseJS WorksNesting and populating MongooseJS SchemasWhen can we use nested schemas?Many-to-oneOne-to-manyOne-to-o...
MEAN Stack SuperpowersNodeJS is not just a Javascript web server- Event based concurrency- Package manager similar to Rail...
Example: Bitcoins!
Bitcoin P&LStep 1 : Web app to display a streaming Bitcoin ticker- Complex problem – multiple threads, sockets, mutex, etc...
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&LTakeaways- General problem : your server connecting to other servers- Example : Ascot links- Can write multi-th...
Bitcoin P&L + MongoDBModel – list of nested stock schemas Routes – get list of stocks, add a new stock
Bitcoin P&L + MongoDBAngularJS – generic no-reload form wrapper
Bitcoin P&L + MongoDBJade – A View To A Kill And the result:
Takeaways- MEAN Stack is awesome- Sophisticated frontends- Multithreaded backends made easy- MongooseJS helps NodeJS and M...
Thanks for Listening!Further Reading- Ascot Project : www.ascotproject.com- AngularJS Form Validation : “How to Easily Val...
Upcoming SlideShare
Loading in …5
×

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

51,237
-1

Published on

Tips and tricks for using MongoDB and Node.js

Published in: Technology
2 Comments
101 Likes
Statistics
Notes
No Downloads
Views
Total Views
51,237
On Slideshare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
671
Comments
2
Likes
101
Embeds 0
No embeds

No notes for slide

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

  1. A Guide to the MEAN StackTips and Tricks for using MongoDB and NodeJSin overwhelmingly awesome waysValeri KarpovCTO, Ascot Projectwww.thecodebarbarian.com@code_barbariangithub.com/vkarpov15
  2. What is The Ascot Project?Making fashion geek-friendlyLess like this More like this
  3. Who is this guy?- Academy for Telecommunications andComputer Science 07, Princeton CS 11- Co-founder and CTO, SCVNGR in 08- Google intern 09, mentored by MiskoHevery- Tower Research Capital 11 – 13- Developed Ascot Project at AngelHackDC in 12
  4. What is this all about?- Why Ascot uses MongoDB- Whats the MEAN stack and why its awesome- How MongoDB fits in the MEAN stack- Why MongooseJS is important and tradeoffs in its usage- Example of a cool MEAN stack web app
  5. Why MongoDB?1) Its cool2) No joins for nested data3) Flexible and simple
  6. SQL is Annoying
  7. MEAN StackWeb dev framework for NodeJSSuperheroic frontend frameworkEvent-based concurrency environment
  8. MEAN Stack – Why do I care?- Write one language- With MongoDB and Mongoose, easy and flexible datavalidation- 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 WorksMongooseJS – 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 WorksMongooseJS – code-defined schemas for MongoDB + NodeJSPrimary 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 WorksA Basic MongooseJS Schema
  13. How MongooseJS WorksUsing the StockPrice Model
  14. How MongooseJS WorksSometimes being able to save anything isnt right
  15. How MongooseJS WorksHelpful Error Messages- Nested JSON errorssummary- Can use this for verygeneric form validation- More on this later
  16. How MongooseJS WorksNesting and populating MongooseJS Schemas – an importantdistinction that doesnt exist in SQLPopulate – similar to SQL joinNest – re-use schema in anotherschema
  17. How MongooseJS WorksCant do multi-level population!
  18. How MongooseJS WorksNesting and populating MongooseJS SchemasWhen can we use nested schemas?Many-to-oneOne-to-manyOne-to-oneMany-to-many
  19. MEAN Stack SuperpowersNodeJS is not just a Javascript web server- Event based concurrency- Package manager similar to Rails gems- Makes multithreaded servers easy
  20. Example: Bitcoins!
  21. Bitcoin P&LStep 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&LTakeaways- 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 + MongoDBModel – list of nested stock schemas Routes – get list of stocks, add a new stock
  26. Bitcoin P&L + MongoDBAngularJS – generic no-reload form wrapper
  27. Bitcoin P&L + MongoDBJade – 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 FormEver Using AngularJS” @ www.thecodebarbarian.com- SocketIO Bitcoin Price Streaming : mtgox-socket-client on NPMand Github- Bitcoin realtime P&L : github.com/vkarpov15/bitcoin-pnl,coming soon to www.thecodebarbarian.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×