Mongoose v3 :: The Future is Bright
Upcoming SlideShare
Loading in...5
×
 

Mongoose v3 :: The Future is Bright

on

  • 24,382 views

See whats ahead in Mongoose v3

See whats ahead in Mongoose v3

Statistics

Views

Total Views
24,382
Views on SlideShare
20,578
Embed Views
3,804

Actions

Likes
18
Downloads
109
Comments
3

18 Embeds 3,804

http://mobicon.tistory.com 1566
http://aaronheckmann.tumblr.com 1051
http://aaronheckmann.posterous.com 628
http://www.scoop.it 510
http://lanyrd.com 18
http://us-w1.rockmelt.com 5
http://feeds.feedburner.com 5
https://si0.twimg.com 5
http://translate.googleusercontent.com 4
http://beta.mural.ly 2
https://twitter.com 2
http://coderwall.com 2
http://dev.newsblur.com 1
http://img.scoop.it 1
http://aaronheckmann.posterous.com&_=1348223792025 HTTP 1
http://nodeslide.herokuapp.com 1
http://posterous.com 1
http://webcache.googleusercontent.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • While I can see that space delimited fields in a query is nice an concise, I think it will limit your future features. e.g. How will you support functions in query in the future? What about nested subqueries? From where I'm standing (as a Mongoose newbie but an experienced SQL dev) stuffing all the field names inside a single text string appear to points to rather limited expressability in the future.
    Are you sure you want to
    Your message goes here
    Processing…
  • Super excited about this!

    Honestly, my biggest frustration with Mongoose has always been that the documentation was about as sparse as you could possibly get. When you're writing up documentation for the new version, PLEASE PLEASE PLEASE try and think of various applications and cases for each part of the documentation, not just one canonical example like exists now.

    For example, even in your slide talking about new ways of sorting, you only showed the example for ascending, not descending - which I'm sure would take some kind of modifier. This is an obvious one, but I would just encourage the Mongoose people to put a little more effort into showing multiple examples - they never hurt, only help.

    Thanks so much for working on this wonderful software that I use every day!
    Justin Schier
    @justinschier
    Are you sure you want to
    Your message goes here
    Processing…
  • Like it :)
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • MongoDB is an open source, document-oriented database.\nInstead of storing your data in tables and rows as you would with a relational database, MongoDB lets you store JSON-like documents. \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • falls flat on its face\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Argentina you eat the whole cow.\nWe want the whole MongoDB cow.\n
  • Argentina you eat the whole cow.\nWe want the whole MongoDB cow.\n
  • \n
  • return results\n
  • return a model instance\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • circular buffer\nTTL collections\n
  • MongoDB 2.2\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • query.stream()\n
  • \n
  • \n
  • \n
  • no idea what needs to be done\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • 2 approaches - hit db with two operations or just one\n
  • \n
  • \n
  • \n
  • storing schemas as json\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Last slide, the future of Mongoose is Bright\n
  • \n
  • \n

Mongoose v3 :: The Future is Bright Mongoose v3 :: The Future is Bright Presentation Transcript

  • MONGOOSE V3 Looking ahead jsconf.ar 2012 @aaronheckmann
  • 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 V3What’s Wrong?
  • MONGOOSE V3Beautiful 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 arent 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 youre Dutch.Now is better than never.Although never is often better than *right* now.If the implementation is hard to explain, its a bad idea.If the implementation is easy to explain, it may be a good idea.Namespaces are one honking great idea -- lets do more of those! -- Tim Peters, The Zen of Python http://www.python.org/dev/peps/pep-0020/
  • MONGOOSE V3Beautiful 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 arent special enough to break the rules.Although practicality beats purity. and preferably only oneErrors 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 youre Dutch.Now is better than never.Although never is often better than *right* now.If the implementation is hard to explain, its a bad idea.If the implementation is easy to explain, it may be a good idea.Namespaces are one honking great idea -- lets do more of those! -- Tim Peters, The Zen of Python http://www.python.org/dev/peps/pep-0020/
  • MONGOOSE V3One way
  • MONGOOSE V3One 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 V3One 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 V3One 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 V3One 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 V3One 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 V3http://www.motifake.com/image/demotivational-poster/1106/determination-determination-faceplant-demotivational-posters-1307398930.jpg
  • MONGOOSE V3API 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 V3API pollution Query methods$ne -> ne only -> select({ path: 1 })$mod -> mod exclude -> select({ path: 0 })$exists -> exists run -> exec$elemMatch -> elemMatch notEqualTo -> neasc -> sort({ path: 1 }) wherein -> withindesc -> sort({ path: 0}) fields -> select
  • MONGOOSE V3API pollution Connection methodscreateConnectioncreateSetConnectionconnectconnectSet
  • MONGOOSE V3The Fix?createConnection $nin -> nin $ne -> necreateSetConnection $all -> all $mod -> modconnect $regex -> regex $exists -> existsconnectSet $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 V3The Fix kill all the thingscreateConnection $nin -> nin $ne -> necreateSetConnection $all -> all $mod -> modconnect $regex -> regex $exists -> existsconnectSet $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 V3The Fix kill all the thingscreateConnection $nin -> nin $ne -> necreateSetConnection $all -> all $mod -> modconnect $regex -> regex $exists -> existsconnectSet $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 V3The Fix remove query aliasesCoffee.where(‘flavor’).$in(array).run()
  • MONGOOSE V3The Fix remove query aliasesCoffee.where(‘flavor’).$in(array).run() Coffee.where(‘flavor’).in(array).exec()
  • MONGOOSE V3The Fix remove query aliasesCoffee.where(‘flavor’).$in(array).run() Coffee.where(‘flavor’).in(array).exec()
  • MONGOOSE V3The Fix remove query aliasesCoffee.find().asc(‘flavor’).run()
  • MONGOOSE V3The Fix remove query aliasesCoffee.find().asc(‘flavor’).run() Coffee.find().sort(‘flavor’).exec()
  • MONGOOSE V3The Fix remove query aliasesCoffee.find().asc(‘flavor’).run() Coffee.find().sort(‘flavor’).exec()
  • MONGOOSE V3The Fix Combine connection methodsgoose.createSetConnection(connString)
  • MONGOOSE V3The Fix Combine connection methodsgoose.createSetConnection(connString) goose.createConnection(connString)
  • MONGOOSE V3The Fix Combine connection methodsmongoose.connectSet(connString)
  • MONGOOSE V3The Fix Combine connection methodsmongoose.connectSet(connString) mongoose.connect(connString)
  • MONGOOSE V3What’s Wrong?
  • MONGOOSE V3What’s Wrong? Query method arguments
  • MONGOOSE V3What’s Wrong? Query method argumentsquery.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 V3What’s Wrong? Query method argumentsquery.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 V3The Fix Query method argumentsquery.select(‘include -exclude’)
  • MONGOOSE V3The Fix Query method argumentsquery.select(‘include -exclude’)query.select({ include: 1, exclude: 0 })
  • MONGOOSE V3The Fix Query method argumentsquery.select({ include: 1, exclude: 0 })query.select(‘include -exclude’)query.sort({ include: 1, exclude: 0 })query.sort(‘include -exclude’)
  • MONGOOSE V3Missing MongoDB features
  • MONGOOSE V3Missing MongoDB features
  • MONGOOSE V3Missing MongoDB features
  • MONGOOSE V3Missing MongoDB features•Map Reduce
  • MONGOOSE V3Missing MongoDB features•Map Reduce var o = { map: mapFn, reduce: rFn } Talks.mapReduce(o, function (err, res) { console.log(res) })
  • MONGOOSE V3Missing 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 V3Missing MongoDB features•FindAndModify
  • MONGOOSE V3Missing MongoDB features•FindAndModify // old way var o = { _id: anObjectId } Talks.findOne(o, function (err, doc) { doc.name = ‘peanut butter’; doc.save() })
  • MONGOOSE V3Missing 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 V3Missing MongoDB features•FindAndModify var o = { name: ‘peanut butter’ } Talks.findOneAndRemove(o, function (err, res) { console.log(res) })
  • MONGOOSE V3Missing MongoDB features•FindAndModify Talks.findByIdAndUpdate(id, update, cb) Talks.findByIdAndRemove(id, update, cb)
  • MONGOOSE V3Missing MongoDB features•Map Reduce•FindAndModify•Capped collections * * soon!
  • MONGOOSE V3Missing MongoDB features•Map Reduce•FindAndModify•Capped collections *•Aggregation * * soon!
  • MONGOOSE V3Missing MongoDB features•Aggregation Article.aggregate( { $project : { author : 1, tags : 1 }} , { $unwind : "$tags" } , { $group : { _id : { tags : 1 } , authors : { $addToSet : "$author" } } }); * soon!
  • MONGOOSE V3Missing MongoDB features•Aggregation Article.aggregate( { $project : { author : 1, tags : 1 }} , { $unwind : "$tags" } , { $group : { _id : { tags : 1 } , authors : { $addToSet : "$author" } } }); * soon!
  • MONGOOSE V3Missing MongoDB features•Aggregation Article.aggregate( { $project : { author : 1, tags : 1 }} , { $unwind : "$tags" } , { $group : { _id : { tags : 1 } , authors : { $addToSet : "$author" } } }); * soon!
  • MONGOOSE V3Missing MongoDB features•Aggregation Article.aggregate( { $project : { author : 1, tags : 1 }} , { $unwind : "$tags" } , { $group : { _id : { tags : 1 } , authors : { $addToSet : "$author" } } }); * soon!
  • MONGOOSE V3Missing MongoDB features•Aggregation Article.aggregate( { $project : { author : 1, tags : 1 }} , { $unwind : "$tags" } , { $group : { _id : { tags : 1 } , authors : { $addToSet : "$author" } } }); * soon!
  • MONGOOSE V3Missing MongoDB features•Aggregation Article.aggregate( { $project : { author : 1, tags : 1 }} , { $unwind : "$tags" } , { $group : { _id : { tags : 1 } , authors : { $addToSet : "$author" } } }); * soon!
  • MONGOOSE V3Missing MongoDB features•Map Reduce•FindAndModify•Capped collections *•Aggregation *•Improved geo-spatial support * * soon!
  • MONGOOSE V3Performance
  • MONGOOSE V3Performance•lean queries
  • MONGOOSE V3Performance•lean queries Talks .findOne() .exec(function (err, doc) { // doc.save() })
  • MONGOOSE V3Performance•lean queries Talks .findOne() .setOptions({ lean: true }) .exec(function (err, doc) { // doc.save })
  • MONGOOSE V3Performance•lean queries Talks .findOne() .setOptions({ lean: true }) .exec(function (err, doc) { // doc.save -> undefined })
  • MONGOOSE V3Performance•lean queries•background indexes
  • MONGOOSE V3Performance•lean queries•background indexes•connection pool size?
  • MONGOOSE V3Performance•lean queries•background indexes•connection pool size?•memory usage?
  • MONGOOSE V3General Improvements
  • MONGOOSE V3General Improvements•Improved update command generation for arrays
  • MONGOOSE V3General Improvements•Improved update command generation for arrays var schema = new Schema({ tags: [], name: String })
  • MONGOOSE V3General Improvements•Improved update command generation for arrays var schema = new Schema({ tags: [], name: String }) var Talks = db.model(‘Talk’, schema)
  • MONGOOSE V3General 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 V3General 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 V3General Improvements•Improved update command generation for arrays Object.defineProperty(talk, ‘name’, { get: function () { return this.smth } , set: function (v){ this.smth = v } })
  • MONGOOSE V3General 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 V3General 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 V3General Improvements•Improved update command generation for arrays talk.save() -> var update = {}; update.$set = talk._set; Talks.update({ _id: talk._id }, update, callback)
  • MONGOOSE V3General Improvements•Improved update command generation for arrays talk.tags.push = function () { record(‘push’, arguments) }
  • MONGOOSE V3General 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 V3General Improvements•Improved update command generation for arrays talk.tags.push(‘nerdcore’) talk.tags.remove(‘php’) talk.save(callback) // fail!
  • MONGOOSE V3General Improvements•Improved update command generation for arrays talk.tags.push(‘nerdcore’) talk.tags.remove(‘php’) talk.save(callback) // success!!
  • MONGOOSE V3General Improvements•Simplify schema declaration
  • MONGOOSE V3General Improvements•Simplify schema declaration var personSchema = new Schema({ name: String , val: Number , buffer: Buffer , array: Array , etc: ... })
  • MONGOOSE V3General Improvements•Simplify schema declaration var personSchema = new Schema({ name: ‘string’ , val: ‘number’ , buffer: ‘buffer’ , array: ‘array’ , etc: ... })
  • MONGOOSE V3General Improvements•Hardened schema ‘strict’ option var personSchema = new Schema({ name: ‘string’ , val: ‘number’ , buffer: ‘buffer’ , array: ‘array’ , etc: ... }, { strict: true })
  • MONGOOSE V3General Improvements•Hardened schema ‘strict’ option var personSchema = new Schema({ name: ‘string’ , val: ‘number’ , buffer: ‘buffer’ , array: ‘array’ , etc: ... }, { strict: ‘throw’ })
  • MONGOOSE V3General Improvements•Hardened schema ‘strict’ option new Person({ notExists: ‘3vil’ })
  • MONGOOSE V3General Improvements•Hardened schema ‘strict’ option new Person({ notExists: ‘3vil’ }) // throws “Field `notExists` is not in schema”
  • MONGOOSE V3General Improvements•Simplify schema declaration•Hardened schema ‘strict’ option (throws)•Removed MongooseNumber
  • MONGOOSE V3General Improvements•Simplify schema declaration•Hardened schema ‘strict’ option (throws)•Removed MongooseNumber•Add multiple validators
  • MONGOOSE V3General Improvements•Simplify schema declaration•Hardened schema ‘strict’ option (throws)•Removed MongooseNumber•Add multiple validators•toObject,toJSON options
  • MONGOOSE V3General Improvements•Simplify schema declaration•Hardened schema ‘strict’ option (throws)•Removed MongooseNumber•Add multiple validators•toObject,toJSON options•Specify a model in query.populate()
  • MONGOOSE V3General Improvements•Add document versioning * soon!
  • MONGOOSE V3General Improvements•Add document versioning•Recursive populate * soon!
  • MONGOOSE V3Documentation•mongoosejs.com•plugins.mongoosejs.com•blog.mongoosejs.com
  • MONGOOSE V3Support•LearnBoost
  • MONGOOSE V3Support•LearnBoost•10gen *
  • MONGOOSE V3Support•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