js-il keynote: mongodb 2.6, mongoose 4.0, and beyond

19
MongoDB 2.6, Mongoose 4.0, and Beyond NodeJS and MongoDB meets ES6 and Browserify Valeri Karpov Software Engineer, MongoDB www.thecodebarbarian.com www.slideshare.net/vkarpov15 github.com/vkarpov15 @code_barbarian

Upload: valeri-karpov

Post on 15-Jan-2015

299 views

Category:

Technology


3 download

DESCRIPTION

 

TRANSCRIPT

Page 1: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

MongoDB 2.6, Mongoose 4.0, and Beyond

NodeJS and MongoDB meets ES6 and Browserify

Valeri KarpovSoftware Engineer, MongoDBwww.thecodebarbarian.com

www.slideshare.net/vkarpov15github.com/vkarpov15

@code_barbarian

Page 2: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Who Am I?

•CI/NodeJS Engineer at MongoDB

•Maintainer of mongoose ODM

•Former CTO, LevelUp

•MEAN stack apps: Ascot Project, Bookalokal

Page 3: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Talk Overview

•Exciting developments in JavaScript:• ECMAScript 6 (Harmony) is coming

• Browserify is changing the way we use NodeJS

• Compiles NodeJS code into browser-friendly form

•Mongoose 4.0 (ETA September) + ES6 + Browserify

•Also highlight some new features in MongoDB 2.6

Page 4: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

What is Mongoose?

•Elegant ODM for MongoDB and NodeJS

•ActiveRecord-like Models per MongoDB collection

•Syntactic sugar for queries: chaining, fluent syntax• ex: .find().where('answer').equals(42)

•Join-like functionality via populate()

•Promises/A+ conformant promises

•Community authored (same author as socket.io)

Page 5: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Part I: ES6 Generators and mongoose

Page 6: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Generators in ECMAScript 6

•ES6 will include a yield keyword

•Write async code with less pyramid of doom

•NodeJS 0.11.x, use node --harmony

Page 7: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Using Generators in ECMAScript 6

•Still need library, such as Q or co

•Special syntax for a function that can yield:• function*() {}

Page 8: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Attaining Harmony with Generators

•yield enables try/catch for async code

•Elegant replacement for async.parallel()

Page 9: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Using yield with mongoose

•MongoDB 2.6 text search (mongoose >= 3.8.9)

Page 10: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Batch save in mongoose

•Without yield:

Page 11: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Batch save in mongoose with yield

Page 12: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Part II: Mongoose in the Browser

Page 13: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Browserify-friendly Schemas

•The dream: same schema in browser and server

•Simplicity: one schema, one language, one validation function

Page 14: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

The Dream Made Real

Page 15: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

The Dream Made Real, Part II

Page 16: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

From Humble Beginnings

Page 17: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Browserify Schema Status

•Very very rough proof of concept, not alpha-ready

•Branch on Github

•Also supports ES6 generators :)

Page 18: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Review

•JavaScript has a very exciting future

•ES6 Generators make async code human-readable

•Browserify makes code sharing a reality

•Mongoose will take advantage of this tech

•My talk at 11:45: 1 hour to build a MEAN stack app with mongoose and browserify

Page 19: JS-IL Keynote: MongoDB 2.6, Mongoose 4.0, and Beyond

*

Thanks for Listening!

•Slides on:• Twitter: @code_barbarian

• Slideshare: slideshare.net/vkarpov15

•Mongoose on Github