Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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


Published on

Tips and tricks for using MongoDB and Node.js

Published in: Technology

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
  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 : AngularJS Form Validation : “How to Easily Validate Any FormEver Using AngularJS” @ SocketIO Bitcoin Price Streaming : mtgox-socket-client on NPMand Github- Bitcoin realtime P&L :,coming soon to