SlideShare a Scribd company logo
MONGOOSE V3
   Looking ahead




                          jsconf.ar 2012
                   @aaronheckmann
Mongoose v3 :: The Future is Bright
Mongoose v3 :: The Future is Bright
Mongoose v3 :: The Future is Bright
MONGOOSE V3
MONGOOSE V3
•What’s wrong
MONGOOSE V3
•What’s wrong
•The Fix
MONGOOSE V3
•What’s wrong
•The Fix
•Improvements
MONGOOSE V3
•What’s wrong
•The Fix
•Improvements
•Support
MONGOOSE V3
  The Future Is Bright
MONGOOSE V3
What’s Wrong?
MONGOOSE V3
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!


 -- Tim Peters,    The Zen of Python     http://www.python.org/dev/peps/pep-0020/
MONGOOSE V3
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.

       There should be one--
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.


         and preferably only one
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.

        --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!


 -- Tim Peters,    The Zen of Python     http://www.python.org/dev/peps/pep-0020/
MONGOOSE V3
One way
MONGOOSE V3
One way


 User.where(‘age’).$gt(17).select(‘name’).exec(cb)
 User.where(‘age’).gt(17).select({‘name’: 1}).exec(cb)
 User.where(‘age’).gt(17).select(‘name’, 1).run(cb)
 User.find({ age: { $gt: 17 }}).select([‘name’]).exec(cb)
 User.find({ age: { $gt: 17 }}, [‘name’]).run(cb)
MONGOOSE V3
One way


 User.where(‘age’).$gt(17).select(‘name’).exec(cb)
 User.where(‘age’).gt(17).select({‘name’: 1}).exec(cb)
 User.where(‘age’).gt(17).select(‘name’, 1).run(cb)
 User.find({ age: { $gt: 17 }}).select([‘name’]).exec(cb)
 User.find({ age: { $gt: 17 }}, [‘name’]).run(cb)
MONGOOSE V3
One way


 User.where(‘age’).$gt(17).select(‘name’).exec(cb)
 User.where(‘age’).gt(17).select({‘name’: 1}).exec(cb)
 User.where(‘age’).gt(17).select(‘name’, 1).run(cb)
 User.find({ age: { $gt: 17 }}).select([‘name’]).exec(cb)
 User.find({ age: { $gt: 17 }}, [‘name’]).run(cb)
MONGOOSE V3
One way


 User.where(‘age’).$gt(17).select(‘name’).exec(cb)
 User.where(‘age’).gt(17).select({‘name’: 1}).exec(cb)
 User.where(‘age’).gt(17).select(‘name’, 1).run(cb)
 User.find({ age: { $gt: 17 }}).select([‘name’]).exec(cb)
 User.find({ age: { $gt: 17 }}, [‘name’]).run(cb)
MONGOOSE V3
One way


 User.where(‘age’).$gt(17).select(‘name’).exec(cb)
 User.where(‘age’).gt(17).select({‘name’: 1}).exec(cb)
 User.where(‘age’).gt(17).select(‘name’, 1).run(cb)
 User.find({ age: { $gt: 17 }}).select([‘name’]).exec(cb)
 User.find({ age: { $gt: 17 }}, [‘name’]).run(cb)
MONGOOSE V3




http://www.motifake.com/image/demotivational-poster/1106/determination-determination-faceplant-demotivational-posters-1307398930.jpg
MONGOOSE V3
API pollution
 Query methods

$or -> or     $in -> in         $near -> near
$nor -> nor   $nin -> nin       $within -> within
$gt -> gt     $all -> all       $box -> box
$gte -> gte   $regex ->regex    $center - > center
$lt -> lt     $size -> size     $centerSphere -> centerSphere
$lte -> lte   $slice -> slice   $maxDistance ->maxDistance
MONGOOSE V3
API pollution
 Query methods

$ne -> ne                  only -> select({ path: 1 })
$mod -> mod                exclude -> select({ path: 0 })
$exists -> exists          run -> exec
$elemMatch -> elemMatch    notEqualTo -> ne
asc -> sort({ path: 1 })   wherein -> within
desc -> sort({ path: 0})   fields -> select
MONGOOSE V3
API pollution
 Connection methods

createConnection
createSetConnection
connect
connectSet
MONGOOSE V3
The Fix?


createConnection       $nin -> nin                     $ne -> ne
createSetConnection    $all -> all                     $mod -> mod
connect                $regex -> regex                 $exists -> exists
connectSet             $size -> size                   $elemMatch -> elemMatch
$or -> or              $slice -> slice                 asc -> sort({ path: 1 })
$nor -> nor            $near -> near                   desc -> sort({ path: 0})
$gt -> gt              $within -> within               only -> select({ path: 1 })
$gte -> gte            $box -> box                     exclude -> select({ path: 0 })
$lt -> lt              $center -> center               run -> exec
$lte -> lte            $centerSphere -> centerSphere   notEqualTo -> ne
$in -> in              $maxDistance -> maxDistance     wherein -> within
                                                       fields -> select
MONGOOSE V3
The Fix
 kill all the things

createConnection       $nin -> nin                     $ne -> ne
createSetConnection    $all -> all                     $mod -> mod
connect                $regex -> regex                 $exists -> exists
connectSet             $size -> size                   $elemMatch -> elemMatch
$or -> or              $slice -> slice                 asc -> sort({ path: 1 })
$nor -> nor            $near -> near                   desc -> sort({ path: 0})
$gt -> gt              $within -> within               only -> select({ path: 1 })
$gte -> gte            $box -> box                     exclude -> select({ path: 0 })
$lt -> lt              $center -> center               run -> exec
$lte -> lte            $centerSphere -> centerSphere   notEqualTo -> ne
$in -> in              $maxDistance -> maxDistance     wherein -> within
                                                       fields -> select
MONGOOSE V3
The Fix
 kill all the things

createConnection       $nin -> nin                     $ne -> ne
createSetConnection    $all -> all                     $mod -> mod
connect                $regex -> regex                 $exists -> exists
connectSet             $size -> size                   $elemMatch -> elemMatch
$or -> or              $slice -> slice                 asc -> sort({ path: 1 })
$nor -> nor            $near -> near                   desc -> sort({ path: 0})
$gt -> gt              $within -> within               only -> select({ path: 1 })
$gte -> gte            $box -> box                     exclude -> select({ path: 0 })
$lt -> lt              $center -> center               run -> exec
$lte -> lte            $centerSphere -> centerSphere   notEqualTo -> ne
$in -> in              $maxDistance -> maxDistance     wherein -> within
                                                       fields -> select


                                                         http://soundbible.com/1575-High-Definition-Machine-Gun.html
                                                         http://openclipart.org/detail/20561/set-of-bullet-holes-by-rg1024
MONGOOSE V3
The Fix
 remove query aliases

Coffee.where(‘flavor’).$in(array).run()
MONGOOSE V3
The Fix
 remove query aliases

Coffee.where(‘flavor’).$in(array).run()   Coffee.where(‘flavor’).in(array).exec()
MONGOOSE V3
The Fix
 remove query aliases

Coffee.where(‘flavor’).$in(array).run()   Coffee.where(‘flavor’).in(array).exec()
MONGOOSE V3
The Fix
 remove query aliases

Coffee.find().asc(‘flavor’).run()
MONGOOSE V3
The Fix
 remove query aliases

Coffee.find().asc(‘flavor’).run()   Coffee.find().sort(‘flavor’).exec()
MONGOOSE V3
The Fix
 remove query aliases

Coffee.find().asc(‘flavor’).run()   Coffee.find().sort(‘flavor’).exec()
MONGOOSE V3
The Fix
 Combine connection methods

goose.createSetConnection(connString)
MONGOOSE V3
The Fix
 Combine connection methods

goose.createSetConnection(connString)


                                        goose.createConnection(connString)
MONGOOSE V3
The Fix
 Combine connection methods

mongoose.connectSet(connString)
MONGOOSE V3
The Fix
 Combine connection methods

mongoose.connectSet(connString)


                                  mongoose.connect(connString)
MONGOOSE V3
What’s Wrong?
MONGOOSE V3
What’s Wrong?
 Query method arguments
MONGOOSE V3
What’s Wrong?
 Query method arguments

query.select(array)
query.select(‘path’, 1, ‘path’, 1)
query.select({ key: 0 })
query.select(‘space delimited’)

query.hint(‘path’, 1, ‘path’, 1)
query.hint({ key: 1})
MONGOOSE V3
What’s Wrong?
 Query method arguments

query.select(array)
query.select(‘path’, 1, ‘path’, 1)
query.select({ key: 0 })
query.select(‘space delimited’)

query.hint(‘path’, 1, ‘path’, 1)
query.hint({ key: 1})
MONGOOSE V3
The Fix
 Query method arguments

query.select(‘include -exclude’)
MONGOOSE V3
The Fix
 Query method arguments

query.select(‘include -exclude’)
query.select({ include: 1, exclude: 0 })
MONGOOSE V3
The Fix
 Query method arguments

query.select({ include: 1, exclude: 0 })
query.select(‘include -exclude’)

query.sort({ include: 1, exclude: 0 })
query.sort(‘include -exclude’)
MONGOOSE V3
Missing MongoDB features
MONGOOSE V3
Missing MongoDB features
MONGOOSE V3
Missing MongoDB features
MONGOOSE V3
Missing MongoDB features

•Map Reduce
MONGOOSE V3
Missing MongoDB features

•Map Reduce
 var o = { map: mapFn, reduce: rFn }

 Talks.mapReduce(o, function (err, res) {
    console.log(res)
 })
MONGOOSE V3
Missing MongoDB features

•Map Reduce
 var o = { map: mapFn, reduce: rFn }
 o.out = { replace: ‘mapped_talks’ }

 Talks.mapReduce(o, function (err, res) {
    res.find().where().exec(function (err, docs) {
       console.log(res)
    })
 })
MONGOOSE V3
Missing MongoDB features

•FindAndModify
MONGOOSE V3
Missing MongoDB features

•FindAndModify
 // old way
 var o = { _id: anObjectId }

 Talks.findOne(o, function (err, doc) {
    doc.name = ‘peanut butter’;
    doc.save()
 })
MONGOOSE V3
Missing MongoDB features

•FindAndModify
 // new way
 var o = { _id: anObjectId }
   , up = { $set: { name: ‘peanut butter’}}

 Talks.findOneAndUpdate(o, up, function (err, doc) {
    console.log(doc)
 })
MONGOOSE V3
Missing MongoDB features

•FindAndModify
 var o = { name: ‘peanut butter’ }

 Talks.findOneAndRemove(o, function (err, res) {
    console.log(res)
 })
MONGOOSE V3
Missing MongoDB features

•FindAndModify
 Talks.findByIdAndUpdate(id, update, cb)
 Talks.findByIdAndRemove(id, update, cb)
MONGOOSE V3
Missing MongoDB features

•Map Reduce
•FindAndModify
•Capped collections *




                            * soon!
MONGOOSE V3
Missing MongoDB features

•Map Reduce
•FindAndModify
•Capped collections *
•Aggregation *



                            * soon!
MONGOOSE V3
Missing MongoDB features

•Aggregation
  Article.aggregate(
      { $project : { author : 1, tags : 1 }}
    , { $unwind : "$tags" }
    , { $group : {
          _id : { tags : 1 }
        , authors : { $addToSet : "$author" }
      }
  });

                                                * soon!
MONGOOSE V3
Missing MongoDB features

•Aggregation
  Article.aggregate(
      { $project : { author : 1, tags : 1 }}
    , { $unwind : "$tags" }
    , { $group : {
          _id : { tags : 1 }
        , authors : { $addToSet : "$author" }
      }
  });

                                                * soon!
MONGOOSE V3
Missing MongoDB features

•Aggregation
  Article.aggregate(
      { $project : { author : 1, tags : 1 }}
    , { $unwind : "$tags" }
    , { $group : {
          _id : { tags : 1 }
        , authors : { $addToSet : "$author" }
      }
  });

                                                * soon!
MONGOOSE V3
Missing MongoDB features

•Aggregation
  Article.aggregate(
      { $project : { author : 1, tags : 1 }}
    , { $unwind : "$tags" }
    , { $group : {
          _id : { tags : 1 }
        , authors : { $addToSet : "$author" }
      }
  });

                                                * soon!
MONGOOSE V3
Missing MongoDB features

•Aggregation
  Article.aggregate(
      { $project : { author : 1, tags : 1 }}
    , { $unwind : "$tags" }
    , { $group : {
          _id : { tags : 1 }
        , authors : { $addToSet : "$author" }
      }
  });

                                                * soon!
MONGOOSE V3
Missing MongoDB features

•Aggregation
  Article.aggregate(
      { $project : { author : 1, tags : 1 }}
    , { $unwind : "$tags" }
    , { $group : {
          _id : { tags : 1 }
        , authors : { $addToSet : "$author" }
      }
  });

                                                * soon!
MONGOOSE V3
Missing MongoDB features

•Map Reduce
•FindAndModify
•Capped collections *
•Aggregation *
•Improved geo-spatial support *


                                  * soon!
MONGOOSE V3
Performance
MONGOOSE V3
Performance

•lean queries
MONGOOSE V3
Performance

•lean queries

 Talks
 .findOne()
 .exec(function (err, doc) {
    // doc.save()
 })
MONGOOSE V3
Performance

•lean queries

 Talks
 .findOne()
 .setOptions({ lean: true })
 .exec(function (err, doc) {
    // doc.save
 })
MONGOOSE V3
Performance

•lean queries

 Talks
 .findOne()
 .setOptions({ lean: true })
 .exec(function (err, doc) {
    // doc.save -> undefined
 })
MONGOOSE V3
Performance

•lean queries
•background indexes
MONGOOSE V3
Performance

•lean queries
•background indexes
•connection pool size?
MONGOOSE V3
Performance

•lean queries
•background indexes
•connection pool size?
•memory usage?
MONGOOSE V3
General Improvements
MONGOOSE V3
General Improvements

•Improved update command generation for arrays
MONGOOSE V3
General Improvements

•Improved update command generation for arrays
 var schema = new Schema({ tags: [], name: String })
MONGOOSE V3
General Improvements

•Improved update command generation for arrays
 var schema = new Schema({ tags: [], name: String })
 var Talks = db.model(‘Talk’, schema)
MONGOOSE V3
General Improvements

•Improved update command generation for arrays
 var schema = new Schema({ tags: [], name: String })
 var Talks = db.model(‘Talk’, schema)
 Talks.findById(id, function (err, talk) {
    talk.name = ‘peanut butter’
    talk.tags.push(‘nerdcore’)
    talk.save(callback)
 })
MONGOOSE V3
General Improvements

•Improved update command generation for arrays
 var schema = new Schema({ tags: [], name: String })
 var Talks = db.model(‘Talk’, schema)
 Talks.findById(id, function (err, talk) {
    talk.name = ‘peanut butter’
    talk.tags.push(‘nerdcore’)
    talk.save(callback) // magic!
 })
MONGOOSE V3
General Improvements

•Improved update command generation for arrays
 Object.defineProperty(talk, ‘name’, {
      get: function () { return this.smth }
    , set: function (v){
        this.smth = v
      }
 })
MONGOOSE V3
General Improvements

•Improved update command generation for arrays
 Object.defineProperty(talk, ‘name’, {
      get: function () { return this.smth }
    , set: function (v){
        record(‘name’);
        this.smth = v
      }
 })
MONGOOSE V3
General Improvements

•Improved update command generation for arrays
 Object.defineProperty(talk, ‘name’, {
      get: function () { return this.smth }
    , set: function (v){
        this._set = {}
        this._set[‘name’] = v
        this.smth = v
      }
 })
MONGOOSE V3
General Improvements

•Improved update command generation for arrays
 talk.save() ->
   var update = {};
   update.$set = talk._set;
   Talks.update({ _id: talk._id }, update, callback)
MONGOOSE V3
General Improvements

•Improved update command generation for arrays
 talk.tags.push = function () {
   record(‘push’, arguments)
 }
MONGOOSE V3
General Improvements

•Improved update command generation for arrays
 talk.tags.push = function () {
   record(‘push’, arguments)
 }

 talk.save() ->
   var update = {};
   update.$pushAll = { tags: args }
   Talk.update({_id:talk._id}, update, callback)
MONGOOSE V3
General Improvements

•Improved update command generation for arrays
 talk.tags.push(‘nerdcore’)
 talk.tags.remove(‘php’)
 talk.save(callback) // fail!
MONGOOSE V3
General Improvements

•Improved update command generation for arrays
 talk.tags.push(‘nerdcore’)
 talk.tags.remove(‘php’)
 talk.save(callback) // success!!
MONGOOSE V3
General Improvements

•Simplify schema declaration
MONGOOSE V3
General Improvements

•Simplify schema declaration
  var personSchema = new Schema({
       name: String
     , val: Number
     , buffer: Buffer
     , array: Array
     , etc: ...
  })
MONGOOSE V3
General Improvements

•Simplify schema declaration
  var personSchema = new Schema({
       name: ‘string’
     , val: ‘number’
     , buffer: ‘buffer’
     , array: ‘array’
     , etc: ...
  })
MONGOOSE V3
General Improvements

•Hardened schema ‘strict’ option
  var personSchema = new Schema({
      name: ‘string’
    , val: ‘number’
    , buffer: ‘buffer’
    , array: ‘array’
    , etc: ...
  }, { strict: true })
MONGOOSE V3
General Improvements

•Hardened schema ‘strict’ option
  var personSchema = new Schema({
      name: ‘string’
    , val: ‘number’
    , buffer: ‘buffer’
    , array: ‘array’
    , etc: ...
  }, { strict: ‘throw’ })
MONGOOSE V3
General Improvements

•Hardened schema ‘strict’ option

  new Person({ notExists: ‘3vil’ })
MONGOOSE V3
General Improvements

•Hardened schema ‘strict’ option

  new Person({ notExists: ‘3vil’ })
  // throws “Field `notExists` is not in schema”
MONGOOSE V3
General Improvements

•Simplify schema declaration
•Hardened schema ‘strict’ option (throws)
•Removed MongooseNumber
MONGOOSE V3
General Improvements

•Simplify schema declaration
•Hardened schema ‘strict’ option (throws)
•Removed MongooseNumber
•Add multiple validators
MONGOOSE V3
General Improvements

•Simplify schema declaration
•Hardened schema ‘strict’ option (throws)
•Removed MongooseNumber
•Add multiple validators
•toObject,toJSON options
MONGOOSE V3
General Improvements

•Simplify schema declaration
•Hardened schema ‘strict’ option (throws)
•Removed MongooseNumber
•Add multiple validators
•toObject,toJSON options
•Specify a model in query.populate()
MONGOOSE V3
General Improvements

•Add document versioning




                           * soon!
MONGOOSE V3
General Improvements

•Add document versioning
•Recursive populate




                           * soon!
MONGOOSE V3
Documentation

•mongoosejs.com
•plugins.mongoosejs.com
•blog.mongoosejs.com
MONGOOSE V3
Support

•LearnBoost
MONGOOSE V3
Support

•LearnBoost
•10gen *
MONGOOSE V3
Support

•LearnBoost
•10gen * driver too
MONGOOSE V3

                 ¿Preguntas?
@aaronheckmann                   aaronheckmann@gmail.com
@10gen                         https://github.com/aheckmann
@learnboost       https://github.com/LearnBoost/mongoose
@mongodb
MONGOOSE V3

                 Thanks!
@aaronheckmann                  aaronheckmann@gmail.com
@10gen                        https://github.com/aheckmann
@learnboost      https://github.com/LearnBoost/mongoose
@mongodb

More Related Content

DOC
PPTX
Groovy puzzlers jug-moscow-part 2
PDF
Connecting XForms to Databases: An Extension to the XForms Markup Language
PDF
php plus mysql
PDF
Programming Lisp Clojure - 2장 : 클로저 둘러보기
PPT
Mocking Dependencies in PHPUnit
PDF
Php code for online quiz
Groovy puzzlers jug-moscow-part 2
Connecting XForms to Databases: An Extension to the XForms Markup Language
php plus mysql
Programming Lisp Clojure - 2장 : 클로저 둘러보기
Mocking Dependencies in PHPUnit
Php code for online quiz

What's hot (20)

PDF
Pre-Bootcamp introduction to Elixir
PDF
PHP tips and tricks
KEY
Document Classification In PHP
KEY
Document Classification In PHP - Slight Return
PPT
PHP and MySQL
PDF
Dip Your Toes in the Sea of Security (PHP South Africa 2017)
PDF
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
PDF
Climbing the Abstract Syntax Tree (PHP South Africa 2017)
PDF
R57shell
PPT
An Elephant of a Different Colour: Hack
PDF
Slaying the Dragon: Implementing a Programming Language in Ruby
PDF
Taking Perl to Eleven with Higher-Order Functions
KEY
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
PDF
Why Hacking WordPress Search Isn't Some Big Scary Thing
PPT
PHP Tutorial (funtion)
PPT
Functional Pe(a)rls version 2
PDF
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
PDF
RxSwift 시작하기
PDF
Teaching Your Machine To Find Fraudsters
PDF
Top 10 php classic traps confoo
Pre-Bootcamp introduction to Elixir
PHP tips and tricks
Document Classification In PHP
Document Classification In PHP - Slight Return
PHP and MySQL
Dip Your Toes in the Sea of Security (PHP South Africa 2017)
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Climbing the Abstract Syntax Tree (PHP South Africa 2017)
R57shell
An Elephant of a Different Colour: Hack
Slaying the Dragon: Implementing a Programming Language in Ruby
Taking Perl to Eleven with Higher-Order Functions
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Why Hacking WordPress Search Isn't Some Big Scary Thing
PHP Tutorial (funtion)
Functional Pe(a)rls version 2
Swift - 혼자 공부하면 분명히 안할테니까 같이 공부하기
RxSwift 시작하기
Teaching Your Machine To Find Fraudsters
Top 10 php classic traps confoo
Ad

Viewers also liked (20)

PPTX
Sharding
KEY
MongoFr : MongoDB as a log Collector
PPT
MongoDB Basic Concepts
PPTX
Scalable Event Analytics with MongoDB & Ruby on Rails
PPTX
MongoDB's New Aggregation framework
PPT
Mongo Web Apps: OSCON 2011
PDF
Grid FS
PDF
Building a Single-Page App: Backbone, Node.js, and Beyond
KEY
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
PDF
Node-IL Meetup 12/2
PDF
Nodejs mongoose
DOCX
Mongoose getting started-Mongo Db with Node js
PDF
IBM MQ - better application performance
PDF
Getting Started With MongoDB and Mongoose
PPTX
Express JS
PDF
Javascript framework and backbone
PDF
The SPDY Protocol
PPTX
Document validation in MongoDB 3.2
PPTX
영속성 컨텍스트로 보는 JPA
PPTX
Becoming Node.js ninja on Cloud Foundry
Sharding
MongoFr : MongoDB as a log Collector
MongoDB Basic Concepts
Scalable Event Analytics with MongoDB & Ruby on Rails
MongoDB's New Aggregation framework
Mongo Web Apps: OSCON 2011
Grid FS
Building a Single-Page App: Backbone, Node.js, and Beyond
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Node-IL Meetup 12/2
Nodejs mongoose
Mongoose getting started-Mongo Db with Node js
IBM MQ - better application performance
Getting Started With MongoDB and Mongoose
Express JS
Javascript framework and backbone
The SPDY Protocol
Document validation in MongoDB 3.2
영속성 컨텍스트로 보는 JPA
Becoming Node.js ninja on Cloud Foundry
Ad

Similar to Mongoose v3 :: The Future is Bright (20)

PDF
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
PDF
FrozenRails Training
PDF
Full metal mongo
KEY
PHP Development With MongoDB
KEY
PHP Development with MongoDB (Fitz Agard)
PDF
Mongo db 2.2 aggregation like a champ
PDF
Client-side MVC with Backbone.js
PDF
Client-side MVC with Backbone.js (reloaded)
PDF
Inside MongoDB: the Internals of an Open-Source Database
KEY
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
PDF
mongodb-introduction
PDF
De normalised london aggregation framework overview
PDF
Latinoware
PPT
Cypher
PDF
MongoDB, Hadoop and humongous data - MongoSV 2012
PDF
Webinar: Working with Graph Data in MongoDB
ZIP
Postgres is easier
PPTX
Introduction to Underscore.js
PDF
JavaScript Libraries Overview
PDF
Mongo db
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
FrozenRails Training
Full metal mongo
PHP Development With MongoDB
PHP Development with MongoDB (Fitz Agard)
Mongo db 2.2 aggregation like a champ
Client-side MVC with Backbone.js
Client-side MVC with Backbone.js (reloaded)
Inside MongoDB: the Internals of an Open-Source Database
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
mongodb-introduction
De normalised london aggregation framework overview
Latinoware
Cypher
MongoDB, Hadoop and humongous data - MongoSV 2012
Webinar: Working with Graph Data in MongoDB
Postgres is easier
Introduction to Underscore.js
JavaScript Libraries Overview
Mongo db

Recently uploaded (20)

PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PPT
What is a Computer? Input Devices /output devices
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
STKI Israel Market Study 2025 version august
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
1. Introduction to Computer Programming.pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PPTX
TLE Review Electricity (Electricity).pptx
A contest of sentiment analysis: k-nearest neighbor versus neural network
What is a Computer? Input Devices /output devices
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Web App vs Mobile App What Should You Build First.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
NewMind AI Weekly Chronicles - August'25-Week II
Assigned Numbers - 2025 - Bluetooth® Document
gpt5_lecture_notes_comprehensive_20250812015547.pdf
cloud_computing_Infrastucture_as_cloud_p
NewMind AI Weekly Chronicles – August ’25 Week III
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
STKI Israel Market Study 2025 version august
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Zenith AI: Advanced Artificial Intelligence
1. Introduction to Computer Programming.pptx
A comparative study of natural language inference in Swahili using monolingua...
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Hindi spoken digit analysis for native and non-native speakers
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
TLE Review Electricity (Electricity).pptx

Mongoose v3 :: The Future is Bright

  • 1. MONGOOSE V3 Looking ahead jsconf.ar 2012 @aaronheckmann
  • 9. MONGOOSE V3 •What’s wrong •The Fix •Improvements •Support
  • 10. MONGOOSE V3 The Future Is Bright
  • 12. MONGOOSE V3 Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! -- Tim Peters, The Zen of Python http://www.python.org/dev/peps/pep-0020/
  • 13. MONGOOSE V3 Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. There should be one-- Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. and preferably only one Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! -- Tim Peters, The Zen of Python http://www.python.org/dev/peps/pep-0020/
  • 15. MONGOOSE V3 One way User.where(‘age’).$gt(17).select(‘name’).exec(cb) User.where(‘age’).gt(17).select({‘name’: 1}).exec(cb) User.where(‘age’).gt(17).select(‘name’, 1).run(cb) User.find({ age: { $gt: 17 }}).select([‘name’]).exec(cb) User.find({ age: { $gt: 17 }}, [‘name’]).run(cb)
  • 16. MONGOOSE V3 One way User.where(‘age’).$gt(17).select(‘name’).exec(cb) User.where(‘age’).gt(17).select({‘name’: 1}).exec(cb) User.where(‘age’).gt(17).select(‘name’, 1).run(cb) User.find({ age: { $gt: 17 }}).select([‘name’]).exec(cb) User.find({ age: { $gt: 17 }}, [‘name’]).run(cb)
  • 17. MONGOOSE V3 One way User.where(‘age’).$gt(17).select(‘name’).exec(cb) User.where(‘age’).gt(17).select({‘name’: 1}).exec(cb) User.where(‘age’).gt(17).select(‘name’, 1).run(cb) User.find({ age: { $gt: 17 }}).select([‘name’]).exec(cb) User.find({ age: { $gt: 17 }}, [‘name’]).run(cb)
  • 18. MONGOOSE V3 One way User.where(‘age’).$gt(17).select(‘name’).exec(cb) User.where(‘age’).gt(17).select({‘name’: 1}).exec(cb) User.where(‘age’).gt(17).select(‘name’, 1).run(cb) User.find({ age: { $gt: 17 }}).select([‘name’]).exec(cb) User.find({ age: { $gt: 17 }}, [‘name’]).run(cb)
  • 19. MONGOOSE V3 One way User.where(‘age’).$gt(17).select(‘name’).exec(cb) User.where(‘age’).gt(17).select({‘name’: 1}).exec(cb) User.where(‘age’).gt(17).select(‘name’, 1).run(cb) User.find({ age: { $gt: 17 }}).select([‘name’]).exec(cb) User.find({ age: { $gt: 17 }}, [‘name’]).run(cb)
  • 21. MONGOOSE V3 API pollution Query methods $or -> or $in -> in $near -> near $nor -> nor $nin -> nin $within -> within $gt -> gt $all -> all $box -> box $gte -> gte $regex ->regex $center - > center $lt -> lt $size -> size $centerSphere -> centerSphere $lte -> lte $slice -> slice $maxDistance ->maxDistance
  • 22. MONGOOSE V3 API pollution Query methods $ne -> ne only -> select({ path: 1 }) $mod -> mod exclude -> select({ path: 0 }) $exists -> exists run -> exec $elemMatch -> elemMatch notEqualTo -> ne asc -> sort({ path: 1 }) wherein -> within desc -> sort({ path: 0}) fields -> select
  • 23. MONGOOSE V3 API pollution Connection methods createConnection createSetConnection connect connectSet
  • 24. MONGOOSE V3 The Fix? createConnection $nin -> nin $ne -> ne createSetConnection $all -> all $mod -> mod connect $regex -> regex $exists -> exists connectSet $size -> size $elemMatch -> elemMatch $or -> or $slice -> slice asc -> sort({ path: 1 }) $nor -> nor $near -> near desc -> sort({ path: 0}) $gt -> gt $within -> within only -> select({ path: 1 }) $gte -> gte $box -> box exclude -> select({ path: 0 }) $lt -> lt $center -> center run -> exec $lte -> lte $centerSphere -> centerSphere notEqualTo -> ne $in -> in $maxDistance -> maxDistance wherein -> within fields -> select
  • 25. MONGOOSE V3 The Fix kill all the things createConnection $nin -> nin $ne -> ne createSetConnection $all -> all $mod -> mod connect $regex -> regex $exists -> exists connectSet $size -> size $elemMatch -> elemMatch $or -> or $slice -> slice asc -> sort({ path: 1 }) $nor -> nor $near -> near desc -> sort({ path: 0}) $gt -> gt $within -> within only -> select({ path: 1 }) $gte -> gte $box -> box exclude -> select({ path: 0 }) $lt -> lt $center -> center run -> exec $lte -> lte $centerSphere -> centerSphere notEqualTo -> ne $in -> in $maxDistance -> maxDistance wherein -> within fields -> select
  • 26. MONGOOSE V3 The Fix kill all the things createConnection $nin -> nin $ne -> ne createSetConnection $all -> all $mod -> mod connect $regex -> regex $exists -> exists connectSet $size -> size $elemMatch -> elemMatch $or -> or $slice -> slice asc -> sort({ path: 1 }) $nor -> nor $near -> near desc -> sort({ path: 0}) $gt -> gt $within -> within only -> select({ path: 1 }) $gte -> gte $box -> box exclude -> select({ path: 0 }) $lt -> lt $center -> center run -> exec $lte -> lte $centerSphere -> centerSphere notEqualTo -> ne $in -> in $maxDistance -> maxDistance wherein -> within fields -> select http://soundbible.com/1575-High-Definition-Machine-Gun.html http://openclipart.org/detail/20561/set-of-bullet-holes-by-rg1024
  • 27. MONGOOSE V3 The Fix remove query aliases Coffee.where(‘flavor’).$in(array).run()
  • 28. MONGOOSE V3 The Fix remove query aliases Coffee.where(‘flavor’).$in(array).run() Coffee.where(‘flavor’).in(array).exec()
  • 29. MONGOOSE V3 The Fix remove query aliases Coffee.where(‘flavor’).$in(array).run() Coffee.where(‘flavor’).in(array).exec()
  • 30. MONGOOSE V3 The Fix remove query aliases Coffee.find().asc(‘flavor’).run()
  • 31. MONGOOSE V3 The Fix remove query aliases Coffee.find().asc(‘flavor’).run() Coffee.find().sort(‘flavor’).exec()
  • 32. MONGOOSE V3 The Fix remove query aliases Coffee.find().asc(‘flavor’).run() Coffee.find().sort(‘flavor’).exec()
  • 33. MONGOOSE V3 The Fix Combine connection methods goose.createSetConnection(connString)
  • 34. MONGOOSE V3 The Fix Combine connection methods goose.createSetConnection(connString) goose.createConnection(connString)
  • 35. MONGOOSE V3 The Fix Combine connection methods mongoose.connectSet(connString)
  • 36. MONGOOSE V3 The Fix Combine connection methods mongoose.connectSet(connString) mongoose.connect(connString)
  • 38. MONGOOSE V3 What’s Wrong? Query method arguments
  • 39. MONGOOSE V3 What’s Wrong? Query method arguments query.select(array) query.select(‘path’, 1, ‘path’, 1) query.select({ key: 0 }) query.select(‘space delimited’) query.hint(‘path’, 1, ‘path’, 1) query.hint({ key: 1})
  • 40. MONGOOSE V3 What’s Wrong? Query method arguments query.select(array) query.select(‘path’, 1, ‘path’, 1) query.select({ key: 0 }) query.select(‘space delimited’) query.hint(‘path’, 1, ‘path’, 1) query.hint({ key: 1})
  • 41. MONGOOSE V3 The Fix Query method arguments query.select(‘include -exclude’)
  • 42. MONGOOSE V3 The Fix Query method arguments query.select(‘include -exclude’) query.select({ include: 1, exclude: 0 })
  • 43. MONGOOSE V3 The Fix Query method arguments query.select({ include: 1, exclude: 0 }) query.select(‘include -exclude’) query.sort({ include: 1, exclude: 0 }) query.sort(‘include -exclude’)
  • 47. MONGOOSE V3 Missing MongoDB features •Map Reduce
  • 48. MONGOOSE V3 Missing MongoDB features •Map Reduce var o = { map: mapFn, reduce: rFn } Talks.mapReduce(o, function (err, res) { console.log(res) })
  • 49. MONGOOSE V3 Missing MongoDB features •Map Reduce var o = { map: mapFn, reduce: rFn } o.out = { replace: ‘mapped_talks’ } Talks.mapReduce(o, function (err, res) { res.find().where().exec(function (err, docs) { console.log(res) }) })
  • 50. MONGOOSE V3 Missing MongoDB features •FindAndModify
  • 51. MONGOOSE V3 Missing MongoDB features •FindAndModify // old way var o = { _id: anObjectId } Talks.findOne(o, function (err, doc) { doc.name = ‘peanut butter’; doc.save() })
  • 52. MONGOOSE V3 Missing MongoDB features •FindAndModify // new way var o = { _id: anObjectId } , up = { $set: { name: ‘peanut butter’}} Talks.findOneAndUpdate(o, up, function (err, doc) { console.log(doc) })
  • 53. MONGOOSE V3 Missing MongoDB features •FindAndModify var o = { name: ‘peanut butter’ } Talks.findOneAndRemove(o, function (err, res) { console.log(res) })
  • 54. MONGOOSE V3 Missing MongoDB features •FindAndModify Talks.findByIdAndUpdate(id, update, cb) Talks.findByIdAndRemove(id, update, cb)
  • 55. MONGOOSE V3 Missing MongoDB features •Map Reduce •FindAndModify •Capped collections * * soon!
  • 56. MONGOOSE V3 Missing MongoDB features •Map Reduce •FindAndModify •Capped collections * •Aggregation * * soon!
  • 57. MONGOOSE V3 Missing MongoDB features •Aggregation Article.aggregate( { $project : { author : 1, tags : 1 }} , { $unwind : "$tags" } , { $group : { _id : { tags : 1 } , authors : { $addToSet : "$author" } } }); * soon!
  • 58. MONGOOSE V3 Missing MongoDB features •Aggregation Article.aggregate( { $project : { author : 1, tags : 1 }} , { $unwind : "$tags" } , { $group : { _id : { tags : 1 } , authors : { $addToSet : "$author" } } }); * soon!
  • 59. MONGOOSE V3 Missing MongoDB features •Aggregation Article.aggregate( { $project : { author : 1, tags : 1 }} , { $unwind : "$tags" } , { $group : { _id : { tags : 1 } , authors : { $addToSet : "$author" } } }); * soon!
  • 60. MONGOOSE V3 Missing MongoDB features •Aggregation Article.aggregate( { $project : { author : 1, tags : 1 }} , { $unwind : "$tags" } , { $group : { _id : { tags : 1 } , authors : { $addToSet : "$author" } } }); * soon!
  • 61. MONGOOSE V3 Missing MongoDB features •Aggregation Article.aggregate( { $project : { author : 1, tags : 1 }} , { $unwind : "$tags" } , { $group : { _id : { tags : 1 } , authors : { $addToSet : "$author" } } }); * soon!
  • 62. MONGOOSE V3 Missing MongoDB features •Aggregation Article.aggregate( { $project : { author : 1, tags : 1 }} , { $unwind : "$tags" } , { $group : { _id : { tags : 1 } , authors : { $addToSet : "$author" } } }); * soon!
  • 63. MONGOOSE V3 Missing MongoDB features •Map Reduce •FindAndModify •Capped collections * •Aggregation * •Improved geo-spatial support * * soon!
  • 66. MONGOOSE V3 Performance •lean queries Talks .findOne() .exec(function (err, doc) { // doc.save() })
  • 67. MONGOOSE V3 Performance •lean queries Talks .findOne() .setOptions({ lean: true }) .exec(function (err, doc) { // doc.save })
  • 68. MONGOOSE V3 Performance •lean queries Talks .findOne() .setOptions({ lean: true }) .exec(function (err, doc) { // doc.save -> undefined })
  • 70. MONGOOSE V3 Performance •lean queries •background indexes •connection pool size?
  • 71. MONGOOSE V3 Performance •lean queries •background indexes •connection pool size? •memory usage?
  • 73. MONGOOSE V3 General Improvements •Improved update command generation for arrays
  • 74. MONGOOSE V3 General Improvements •Improved update command generation for arrays var schema = new Schema({ tags: [], name: String })
  • 75. MONGOOSE V3 General Improvements •Improved update command generation for arrays var schema = new Schema({ tags: [], name: String }) var Talks = db.model(‘Talk’, schema)
  • 76. MONGOOSE V3 General Improvements •Improved update command generation for arrays var schema = new Schema({ tags: [], name: String }) var Talks = db.model(‘Talk’, schema) Talks.findById(id, function (err, talk) { talk.name = ‘peanut butter’ talk.tags.push(‘nerdcore’) talk.save(callback) })
  • 77. MONGOOSE V3 General Improvements •Improved update command generation for arrays var schema = new Schema({ tags: [], name: String }) var Talks = db.model(‘Talk’, schema) Talks.findById(id, function (err, talk) { talk.name = ‘peanut butter’ talk.tags.push(‘nerdcore’) talk.save(callback) // magic! })
  • 78. MONGOOSE V3 General Improvements •Improved update command generation for arrays Object.defineProperty(talk, ‘name’, { get: function () { return this.smth } , set: function (v){ this.smth = v } })
  • 79. MONGOOSE V3 General Improvements •Improved update command generation for arrays Object.defineProperty(talk, ‘name’, { get: function () { return this.smth } , set: function (v){ record(‘name’); this.smth = v } })
  • 80. MONGOOSE V3 General Improvements •Improved update command generation for arrays Object.defineProperty(talk, ‘name’, { get: function () { return this.smth } , set: function (v){ this._set = {} this._set[‘name’] = v this.smth = v } })
  • 81. MONGOOSE V3 General Improvements •Improved update command generation for arrays talk.save() -> var update = {}; update.$set = talk._set; Talks.update({ _id: talk._id }, update, callback)
  • 82. MONGOOSE V3 General Improvements •Improved update command generation for arrays talk.tags.push = function () { record(‘push’, arguments) }
  • 83. MONGOOSE V3 General Improvements •Improved update command generation for arrays talk.tags.push = function () { record(‘push’, arguments) } talk.save() -> var update = {}; update.$pushAll = { tags: args } Talk.update({_id:talk._id}, update, callback)
  • 84. MONGOOSE V3 General Improvements •Improved update command generation for arrays talk.tags.push(‘nerdcore’) talk.tags.remove(‘php’) talk.save(callback) // fail!
  • 85. MONGOOSE V3 General Improvements •Improved update command generation for arrays talk.tags.push(‘nerdcore’) talk.tags.remove(‘php’) talk.save(callback) // success!!
  • 87. MONGOOSE V3 General Improvements •Simplify schema declaration var personSchema = new Schema({ name: String , val: Number , buffer: Buffer , array: Array , etc: ... })
  • 88. MONGOOSE V3 General Improvements •Simplify schema declaration var personSchema = new Schema({ name: ‘string’ , val: ‘number’ , buffer: ‘buffer’ , array: ‘array’ , etc: ... })
  • 89. MONGOOSE V3 General Improvements •Hardened schema ‘strict’ option var personSchema = new Schema({ name: ‘string’ , val: ‘number’ , buffer: ‘buffer’ , array: ‘array’ , etc: ... }, { strict: true })
  • 90. MONGOOSE V3 General Improvements •Hardened schema ‘strict’ option var personSchema = new Schema({ name: ‘string’ , val: ‘number’ , buffer: ‘buffer’ , array: ‘array’ , etc: ... }, { strict: ‘throw’ })
  • 91. MONGOOSE V3 General Improvements •Hardened schema ‘strict’ option new Person({ notExists: ‘3vil’ })
  • 92. MONGOOSE V3 General Improvements •Hardened schema ‘strict’ option new Person({ notExists: ‘3vil’ }) // throws “Field `notExists` is not in schema”
  • 93. MONGOOSE V3 General Improvements •Simplify schema declaration •Hardened schema ‘strict’ option (throws) •Removed MongooseNumber
  • 94. MONGOOSE V3 General Improvements •Simplify schema declaration •Hardened schema ‘strict’ option (throws) •Removed MongooseNumber •Add multiple validators
  • 95. MONGOOSE V3 General Improvements •Simplify schema declaration •Hardened schema ‘strict’ option (throws) •Removed MongooseNumber •Add multiple validators •toObject,toJSON options
  • 96. MONGOOSE V3 General Improvements •Simplify schema declaration •Hardened schema ‘strict’ option (throws) •Removed MongooseNumber •Add multiple validators •toObject,toJSON options •Specify a model in query.populate()
  • 97. MONGOOSE V3 General Improvements •Add document versioning * soon!
  • 98. MONGOOSE V3 General Improvements •Add document versioning •Recursive populate * soon!
  • 103. MONGOOSE V3 ¿Preguntas? @aaronheckmann aaronheckmann@gmail.com @10gen https://github.com/aheckmann @learnboost https://github.com/LearnBoost/mongoose @mongodb
  • 104. MONGOOSE V3 Thanks! @aaronheckmann aaronheckmann@gmail.com @10gen https://github.com/aheckmann @learnboost https://github.com/LearnBoost/mongoose @mongodb

Editor's Notes