SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Battle of the ORM
V
JavaScript ORM
• ORM: Object/relational impedance mismatch
• DAO: Centralized data access
• In JavaScript: A really easy way to configure
collections
Comparison Points
• Getting setup
• Applying constraints
• White/blacklisting properties, data visibility
• Document associations
• Lifecycle hooks
Mongoose Setup
var mongoose=require('mongoose'),

Foo=mongoose.model('Foo',{name:String});

function setupFoo(){

var foo=new Foo({name:'Test Foo'});

foo.save(function(err,foo){

if(err) return console.log(err);

Foo.findOne({_id:foo._id})

.exec(function(err,foo){

if(err) return console.log(err);

if(!foo) console.log(

'Mongoose returns null when findOne returns nothing.');

console.log('Got foo from database,
%s.',JSON.stringify(foo,null,2));

process.exit(0);

});

});

}

mongoose.connect('mongodb://localhost/test');

var db = mongoose.connection;

db.on('error', console.error.bind(console, 'connection error:'));

db.once('open', function () {

setupFoo();

});
Waterline Setup
var Waterline=require('waterline'),orm=new Waterline(),

mongoAdapter=require('sails-mongo'),

config={

adapters:{default:mongoAdapter,mongo:mongoAdapter},

connections:{

localhostMongo:{

adapter: 'mongo',host: 'localhost',port: 27017,database: 'test'

}}};

orm.loadCollection(Waterline.Collection.extend({

identity: 'foo',

connection: 'localhostMongo',

attributes: {name: 'string'}

}));

function setupFoo(Foo){

Foo.create({name:'Test Foo'}).then(function(foo){

Foo.findOne().where({id:foo._id}).then(function(foo){

if(!foo) console.log(

'Waterline returns undefined when findOne returns nothing.');

console.log('Got foo from database, %s.',JSON.stringify(foo,null,2));

process.exit(0);

});

});

}

orm.initialize(config,function(err,models){

if(err) return console.log(err);

setupFoo(models.collections.foo);

});
Setup Results
/usr/local/bin/node mongoose.js
Got foo from database, {
"_id": "558646750d141363a10539ee",
"name": "Test Foo",
"__v": 0
}.
Process finished with exit code 0
/usr/local/bin/node waterline.js
Got foo from database, {
"name": "Test Foo",
"createdAt": "2015-06-21T05:07:35.012Z",
"updatedAt": "2015-06-21T05:07:35.012Z",
"id": "5586469768455964a130adf4"
}.
Process finished with exit code 0
Round 1: Setup
Mongoose
• Fast to setup
• Uses callbacks natively
• Thin wrapper for mongodb
driver
• Provides __v property for
document versioning
Waterline
• Slightly more configuration
• Uses promises natively
• Abstracts data store from
document definition
• Provides created & modified
timestamps
Mongoose Constraints
Foo=mongoose.model('Foo',{name:{type:String,required:true}});

…
function testConstraints(){

var foo=new Foo({});

foo.save(function(err){

console.log(err);

process.exit(1);

});

}

…
db.once('open', function () {

testConstraints();

});
/usr/local/bin/node mongoose.js
{ [ValidationError: Foo validation failed]
message: 'Foo validation failed',
name: 'ValidationError',
errors:
{ name:
{ [ValidatorError: Path `name` is required.]
properties: [Object],
message: 'Path `name` is required.',
name: 'ValidatorError',
kind: 'required',
path: 'name',
value: undefined } } }
Process finished with exit code 1
Waterline Constraints
orm.loadCollection(Waterline.Collection.extend({

identity: 'foo',

connection: 'localhostMongo',

attributes: {name:{type:'string',required:true}}

}));

…
function testConstraints(Foo){

Foo.create({}).catch(function(err){

console.log(err);

process.exit(1);

});

}

orm.initialize(config,function(err,models){

if(err) return console.log(err);

testConstraints(models.collections.foo);

});
/usr/local/bin/node waterline.js
Error (E_VALIDATION) :: 1 attribute is invalid
at WLValidationError.WLError (techdt.la-mvw/node_modules/waterline/
lib/waterline/error/WLError.js:26:15)
…
Invalid attributes sent to foo:
• name
• `undefined` should be a string (instead of "null", which is a
object)
• "required" validation rule failed for input: null
Process finished with exit code 1
Round 2: Constraints
Mongoose
• Flexible constraints to handle
most situations
• Easy to setup
• Somewhat hard to read
validation error messages
• Does not provide stack
information
Waterline
• Flexible constraints to handle
most situations
• Easy to setup
• Easy to read validation error
messages
• Provides stack information to
help debugging
Mongoose Visibility [1]
Foo=mongoose.model('Foo',{

name:{type:String,required:true},

secret:{type:String,select:false}

});

…
function testSecret(){

var foo=new Foo({name:'Test Foo',secret:'123456'});

foo.save(function(err,foo){

if(err) return console.log(err);

console.log(
'Saved foo to database, %s.',JSON.stringify(foo,null,2));

Foo.findOne({_id:foo._id})

.exec(function(err,foo){

if(err) return console.log(err);

if(!foo) console.log(

'Mongoose returns undefined when findOne returns nothing.');

console.log(
'Got foo from database, %s.',JSON.stringify(foo,null,2));

process.exit(0);

});

})

}
/usr/local/bin/node mongoose.js
Saved foo to database, {
"__v": 0,
"name": "Test Foo",
"secret": "123456",
"_id": "55864fdf4e5d5e94a1af5a14"
}.
Got foo from database, {
"_id": "55864fdf4e5d5e94a1af5a14",
"name": "Test Foo",
"__v": 0
}.
Process finished with exit code 0
Mongoose Visibility [2]
FooSchema=new mongoose.Schema({

name:{type:String,required:true},

secret:{type:String,select:false}

},{toJSON:{transform: function (doc,ret) {delete ret.secret;}}}

),

Foo=mongoose.model('Foo',FooSchema);
/usr/local/bin/node mongoose.js
Saved foo to database, {
"__v": 0,
"name": "Test Foo",
"_id": "558654d2945f15a1a1a2d840"
}.
Got foo from database, {
"_id": "558654d2945f15a1a1a2d840",
"name": "Test Foo",
"__v": 0
}.
Process finished with exit code 0
Waterline Visibility
orm.loadCollection(Waterline.Collection.extend({

identity: 'foo',

connection: 'localhostMongo',

attributes: {

name:{type:'string',required:true},

secret:{type:'string'},

toJSON: function() {

var foo= this.toObject();

delete foo.secret;

return foo;

}

}

}));
…
function testSecret(Foo){

Foo.create({name:'Test Foo',secret:123456}).then(function(foo){

console.log(
'Saved foo to database, %s.',JSON.stringify(foo,null,2));

})

}
/usr/local/bin/node waterline.js
Saved foo to database, {
"name": "Test Foo",
"createdAt": "2015-06-21T06:30:44.374Z",
"updatedAt": "2015-06-21T06:30:44.374Z",
"id": "55865a146954cbb4a16fe33e"
}.
Round 3: Visibility
Mongoose
• Two methods to hide
document properties
• One doesn’t work in all cases
• The other is a bit tough to
configure
Waterline
• One method to hide document
properties
• Works in all cases
• Simple to configure
Mongoose Associations
BarSchema=new mongoose.Schema({

name:String,foo:{type:mongoose.Schema.Types.ObjectId,ref:'Foo'}

}),

Bar=mongoose.model('Bar',BarSchema);

…
function testAssociations(){

var foo=new Foo({name:'Test Foo'});

foo.save(function(err,foo){

if(err) return console.log(err);

var bar=new Bar({name:'Test Bar',foo:foo});

bar.save(function(err,bar){

if(err) return console.log(err);

Bar.findOne({_id:bar._id},function(err,bar){

console.log(

'Got bar from database %s.',JSON.stringify(bar,null,2));

bar.populate('foo',function(err,bar){

if(err) return console.log(err);

console.log(

'Populated foo on bar %s.',JSON.stringify(bar,null,2));

process.exit(0);

});

});

});

});

}
/usr/local/bin/node mongoose.js
Got bar from database {
"_id": "55865d0e96b702dba1cecc85",
"name": "Test Bar",
"foo": "55865d0d96b702dba1cecc84",
"__v": 0
}.
Populated foo from database {
"_id": "55865d0e96b702dba1cecc85",
"name": "Test Bar",
"foo": {
"_id": "55865d0d96b702dba1cecc84",
"name": "Test Foo",
"__v": 0
},
"__v": 0
}.
Process finished with exit code 0
Waterline Associations
orm.loadCollection(Waterline.Collection.extend({

identity: 'bar',

connection: 'localhostMongo',

attributes: {

name:{type:'string',required:true},

foo:{model:'foo'}

}

}));
…
function testAssociations(Foo,Bar){

Foo.create({name:'Test Foo'}).then(function(foo){

Bar.create({name:'Test Bar',foo:foo}).then(function(bar){

console.log('Saved bar to database %s.',JSON.stringify(bar,0,2));

Bar.findOne({id:bar.id}).populate('foo').then(function(bar){

console.log('Populated foo on bar %s.',JSON.stringify(bar,0,2));

process.exit(0);

});

});

});

}
/usr/local/bin/node waterline.js
Saved bar to database {
"name": "Test Bar",
"foo": "558660a765f025eba1fbb7af",
"createdAt": "2015-06-21T06:58:47.079Z",
"updatedAt": "2015-06-21T06:58:47.079Z",
"id": "558660a765f025eba1fbb7b0"
}.
Populated foo on bar {
"foo": {
"name": "Test Foo",
"createdAt": "2015-06-21T06:58:47.071Z",
"updatedAt": "2015-06-21T06:58:47.071Z",
"id": "558660a765f025eba1fbb7af"
},
"name": "Test Bar",
"createdAt": "2015-06-21T06:58:47.079Z",
"updatedAt": "2015-06-21T06:58:47.079Z",
"id": "558660a765f025eba1fbb7b0"
}.
Process finished with exit code 0
Round 4: Associations
Mongoose
• Easy to setup document
associations
• Can call populate on find, or
on a document
• Associated documents may or
may not be populated
Waterline
• Easy to setup document
associations
• Associated documents may
live in other databases
• Can only call populate on find
• Associated documents only
populated when requested
Wrap Up
Mongoose
• Mongo ORM for JavaScript
• Has some rough edges
• Only option for highly
concurrent document updates
• Consistently more code to do
the same things
Waterline
• JavaScript ORM for many
popular databases
• More modern, today
JavaScript framework
• Less rough edges
• Does not support document
isolation

Weitere ähnliche Inhalte

Was ist angesagt?

HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
ClojurianからみたElixir
ClojurianからみたElixirClojurianからみたElixir
ClojurianからみたElixirKent Ohashi
 
JS Level Up: Prototypes
JS Level Up: PrototypesJS Level Up: Prototypes
JS Level Up: PrototypesVernon Kesner
 
ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]Guillermo Paz
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016Manoj Kumar
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeCory Forsyth
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6Solution4Future
 
Stuff you didn't know about action script
Stuff you didn't know about action scriptStuff you didn't know about action script
Stuff you didn't know about action scriptChristophe Herreman
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6FITC
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
Djangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New RelicDjangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New RelicNew Relic
 
sizeof(Object): how much memory objects take on JVMs and when this may matter
sizeof(Object): how much memory objects take on JVMs and when this may mattersizeof(Object): how much memory objects take on JVMs and when this may matter
sizeof(Object): how much memory objects take on JVMs and when this may matterDawid Weiss
 
Javascript basics
Javascript basicsJavascript basics
Javascript basicsFin Chen
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the ASTJarrod Overson
 
Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++Sergey Platonov
 

Was ist angesagt? (20)

HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Effective ES6
Effective ES6Effective ES6
Effective ES6
 
ClojurianからみたElixir
ClojurianからみたElixirClojurianからみたElixir
ClojurianからみたElixir
 
JS Level Up: Prototypes
JS Level Up: PrototypesJS Level Up: Prototypes
JS Level Up: Prototypes
 
ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]ES6 in Production [JSConfUY2015]
ES6 in Production [JSConfUY2015]
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7
 
Explaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to ComeExplaining ES6: JavaScript History and What is to Come
Explaining ES6: JavaScript History and What is to Come
 
JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6JavaScript - new features in ECMAScript 6
JavaScript - new features in ECMAScript 6
 
Stuff you didn't know about action script
Stuff you didn't know about action scriptStuff you didn't know about action script
Stuff you didn't know about action script
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Djangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New RelicDjangocon11: Monkeying around at New Relic
Djangocon11: Monkeying around at New Relic
 
sizeof(Object): how much memory objects take on JVMs and when this may matter
sizeof(Object): how much memory objects take on JVMs and when this may mattersizeof(Object): how much memory objects take on JVMs and when this may matter
sizeof(Object): how much memory objects take on JVMs and when this may matter
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
JavaScript and the AST
JavaScript and the ASTJavaScript and the AST
JavaScript and the AST
 
Rust ⇋ JavaScript
Rust ⇋ JavaScriptRust ⇋ JavaScript
Rust ⇋ JavaScript
 
Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++
 

Ähnlich wie Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulmer of HopSkipDrive

An introduction to JVM performance
An introduction to JVM performanceAn introduction to JVM performance
An introduction to JVM performanceRafael Winterhalter
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScriptJohannes Hoppe
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScriptJohannes Hoppe
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesCharles Nutter
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}.toster
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Charles Nutter
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to ScalaTim Underwood
 
Immutability, and how to do it in JavaScripts
Immutability, and how to do it in JavaScriptsImmutability, and how to do it in JavaScripts
Immutability, and how to do it in JavaScriptsAnton Astashov
 
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Comsysto Reply GmbH
 
Orlando BarCamp Why Javascript Doesn't Suck
Orlando BarCamp Why Javascript Doesn't SuckOrlando BarCamp Why Javascript Doesn't Suck
Orlando BarCamp Why Javascript Doesn't Suckerockendude
 
Elixir: the not-so-hidden path to Erlang
Elixir: the not-so-hidden path to ErlangElixir: the not-so-hidden path to Erlang
Elixir: the not-so-hidden path to ErlangLaura M. Castro
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVMRafael Winterhalter
 
MongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in BavariaMongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in BavariaMongoDB
 
Java7 New Features and Code Examples
Java7 New Features and Code ExamplesJava7 New Features and Code Examples
Java7 New Features and Code ExamplesNaresh Chintalcheru
 
Node js
Node jsNode js
Node jshazzaz
 

Ähnlich wie Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulmer of HopSkipDrive (20)

JavaScript Primer
JavaScript PrimerJavaScript Primer
JavaScript Primer
 
An introduction to JVM performance
An introduction to JVM performanceAn introduction to JVM performance
An introduction to JVM performance
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript
 
JavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for DummiesJavaOne 2012 - JVM JIT for Dummies
JavaOne 2012 - JVM JIT for Dummies
 
Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
 
Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}Matthew Eernisse, NodeJs, .toster {webdev}
Matthew Eernisse, NodeJs, .toster {webdev}
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 
Immutability, and how to do it in JavaScripts
Immutability, and how to do it in JavaScriptsImmutability, and how to do it in JavaScripts
Immutability, and how to do it in JavaScripts
 
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
 
Orlando BarCamp Why Javascript Doesn't Suck
Orlando BarCamp Why Javascript Doesn't SuckOrlando BarCamp Why Javascript Doesn't Suck
Orlando BarCamp Why Javascript Doesn't Suck
 
Elixir: the not-so-hidden path to Erlang
Elixir: the not-so-hidden path to ErlangElixir: the not-so-hidden path to Erlang
Elixir: the not-so-hidden path to Erlang
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 
MongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in BavariaMongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in Bavaria
 
Java7 New Features and Code Examples
Java7 New Features and Code ExamplesJava7 New Features and Code Examples
Java7 New Features and Code Examples
 
Node js
Node jsNode js
Node js
 
Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 
Object oriented JavaScript
Object oriented JavaScriptObject oriented JavaScript
Object oriented JavaScript
 
NodeJS
NodeJSNodeJS
NodeJS
 

Mehr von Data Con LA

Data Con LA 2022 Keynotes
Data Con LA 2022 KeynotesData Con LA 2022 Keynotes
Data Con LA 2022 KeynotesData Con LA
 
Data Con LA 2022 Keynotes
Data Con LA 2022 KeynotesData Con LA 2022 Keynotes
Data Con LA 2022 KeynotesData Con LA
 
Data Con LA 2022 Keynote
Data Con LA 2022 KeynoteData Con LA 2022 Keynote
Data Con LA 2022 KeynoteData Con LA
 
Data Con LA 2022 - Startup Showcase
Data Con LA 2022 - Startup ShowcaseData Con LA 2022 - Startup Showcase
Data Con LA 2022 - Startup ShowcaseData Con LA
 
Data Con LA 2022 Keynote
Data Con LA 2022 KeynoteData Con LA 2022 Keynote
Data Con LA 2022 KeynoteData Con LA
 
Data Con LA 2022 - Using Google trends data to build product recommendations
Data Con LA 2022 - Using Google trends data to build product recommendationsData Con LA 2022 - Using Google trends data to build product recommendations
Data Con LA 2022 - Using Google trends data to build product recommendationsData Con LA
 
Data Con LA 2022 - AI Ethics
Data Con LA 2022 - AI EthicsData Con LA 2022 - AI Ethics
Data Con LA 2022 - AI EthicsData Con LA
 
Data Con LA 2022 - Improving disaster response with machine learning
Data Con LA 2022 - Improving disaster response with machine learningData Con LA 2022 - Improving disaster response with machine learning
Data Con LA 2022 - Improving disaster response with machine learningData Con LA
 
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and AtlasData Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and AtlasData Con LA
 
Data Con LA 2022 - Real world consumer segmentation
Data Con LA 2022 - Real world consumer segmentationData Con LA 2022 - Real world consumer segmentation
Data Con LA 2022 - Real world consumer segmentationData Con LA
 
Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...
Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...
Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...Data Con LA
 
Data Con LA 2022 - Moving Data at Scale to AWS
Data Con LA 2022 - Moving Data at Scale to AWSData Con LA 2022 - Moving Data at Scale to AWS
Data Con LA 2022 - Moving Data at Scale to AWSData Con LA
 
Data Con LA 2022 - Collaborative Data Exploration using Conversational AI
Data Con LA 2022 - Collaborative Data Exploration using Conversational AIData Con LA 2022 - Collaborative Data Exploration using Conversational AI
Data Con LA 2022 - Collaborative Data Exploration using Conversational AIData Con LA
 
Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...
Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...
Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...Data Con LA
 
Data Con LA 2022 - Intro to Data Science
Data Con LA 2022 - Intro to Data ScienceData Con LA 2022 - Intro to Data Science
Data Con LA 2022 - Intro to Data ScienceData Con LA
 
Data Con LA 2022 - How are NFTs and DeFi Changing Entertainment
Data Con LA 2022 - How are NFTs and DeFi Changing EntertainmentData Con LA 2022 - How are NFTs and DeFi Changing Entertainment
Data Con LA 2022 - How are NFTs and DeFi Changing EntertainmentData Con LA
 
Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...
Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...
Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...Data Con LA
 
Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...
Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...
Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...Data Con LA
 
Data Con LA 2022- Embedding medical journeys with machine learning to improve...
Data Con LA 2022- Embedding medical journeys with machine learning to improve...Data Con LA 2022- Embedding medical journeys with machine learning to improve...
Data Con LA 2022- Embedding medical journeys with machine learning to improve...Data Con LA
 
Data Con LA 2022 - Data Streaming with Kafka
Data Con LA 2022 - Data Streaming with KafkaData Con LA 2022 - Data Streaming with Kafka
Data Con LA 2022 - Data Streaming with KafkaData Con LA
 

Mehr von Data Con LA (20)

Data Con LA 2022 Keynotes
Data Con LA 2022 KeynotesData Con LA 2022 Keynotes
Data Con LA 2022 Keynotes
 
Data Con LA 2022 Keynotes
Data Con LA 2022 KeynotesData Con LA 2022 Keynotes
Data Con LA 2022 Keynotes
 
Data Con LA 2022 Keynote
Data Con LA 2022 KeynoteData Con LA 2022 Keynote
Data Con LA 2022 Keynote
 
Data Con LA 2022 - Startup Showcase
Data Con LA 2022 - Startup ShowcaseData Con LA 2022 - Startup Showcase
Data Con LA 2022 - Startup Showcase
 
Data Con LA 2022 Keynote
Data Con LA 2022 KeynoteData Con LA 2022 Keynote
Data Con LA 2022 Keynote
 
Data Con LA 2022 - Using Google trends data to build product recommendations
Data Con LA 2022 - Using Google trends data to build product recommendationsData Con LA 2022 - Using Google trends data to build product recommendations
Data Con LA 2022 - Using Google trends data to build product recommendations
 
Data Con LA 2022 - AI Ethics
Data Con LA 2022 - AI EthicsData Con LA 2022 - AI Ethics
Data Con LA 2022 - AI Ethics
 
Data Con LA 2022 - Improving disaster response with machine learning
Data Con LA 2022 - Improving disaster response with machine learningData Con LA 2022 - Improving disaster response with machine learning
Data Con LA 2022 - Improving disaster response with machine learning
 
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and AtlasData Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
 
Data Con LA 2022 - Real world consumer segmentation
Data Con LA 2022 - Real world consumer segmentationData Con LA 2022 - Real world consumer segmentation
Data Con LA 2022 - Real world consumer segmentation
 
Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...
Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...
Data Con LA 2022 - Modernizing Analytics & AI for today's needs: Intuit Turbo...
 
Data Con LA 2022 - Moving Data at Scale to AWS
Data Con LA 2022 - Moving Data at Scale to AWSData Con LA 2022 - Moving Data at Scale to AWS
Data Con LA 2022 - Moving Data at Scale to AWS
 
Data Con LA 2022 - Collaborative Data Exploration using Conversational AI
Data Con LA 2022 - Collaborative Data Exploration using Conversational AIData Con LA 2022 - Collaborative Data Exploration using Conversational AI
Data Con LA 2022 - Collaborative Data Exploration using Conversational AI
 
Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...
Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...
Data Con LA 2022 - Why Database Modernization Makes Your Data Decisions More ...
 
Data Con LA 2022 - Intro to Data Science
Data Con LA 2022 - Intro to Data ScienceData Con LA 2022 - Intro to Data Science
Data Con LA 2022 - Intro to Data Science
 
Data Con LA 2022 - How are NFTs and DeFi Changing Entertainment
Data Con LA 2022 - How are NFTs and DeFi Changing EntertainmentData Con LA 2022 - How are NFTs and DeFi Changing Entertainment
Data Con LA 2022 - How are NFTs and DeFi Changing Entertainment
 
Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...
Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...
Data Con LA 2022 - Why Data Quality vigilance requires an End-to-End, Automat...
 
Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...
Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...
Data Con LA 2022-Perfect Viral Ad prediction of Superbowl 2022 using Tease, T...
 
Data Con LA 2022- Embedding medical journeys with machine learning to improve...
Data Con LA 2022- Embedding medical journeys with machine learning to improve...Data Con LA 2022- Embedding medical journeys with machine learning to improve...
Data Con LA 2022- Embedding medical journeys with machine learning to improve...
 
Data Con LA 2022 - Data Streaming with Kafka
Data Con LA 2022 - Data Streaming with KafkaData Con LA 2022 - Data Streaming with Kafka
Data Con LA 2022 - Data Streaming with Kafka
 

Kürzlich hochgeladen

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Kürzlich hochgeladen (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Big Data Day LA 2015 - Mongoose v/s Waterline: Battle of the ORM by Tim Fulmer of HopSkipDrive

  • 2. JavaScript ORM • ORM: Object/relational impedance mismatch • DAO: Centralized data access • In JavaScript: A really easy way to configure collections
  • 3. Comparison Points • Getting setup • Applying constraints • White/blacklisting properties, data visibility • Document associations • Lifecycle hooks
  • 4. Mongoose Setup var mongoose=require('mongoose'),
 Foo=mongoose.model('Foo',{name:String});
 function setupFoo(){
 var foo=new Foo({name:'Test Foo'});
 foo.save(function(err,foo){
 if(err) return console.log(err);
 Foo.findOne({_id:foo._id})
 .exec(function(err,foo){
 if(err) return console.log(err);
 if(!foo) console.log(
 'Mongoose returns null when findOne returns nothing.');
 console.log('Got foo from database, %s.',JSON.stringify(foo,null,2));
 process.exit(0);
 });
 });
 }
 mongoose.connect('mongodb://localhost/test');
 var db = mongoose.connection;
 db.on('error', console.error.bind(console, 'connection error:'));
 db.once('open', function () {
 setupFoo();
 });
  • 5. Waterline Setup var Waterline=require('waterline'),orm=new Waterline(),
 mongoAdapter=require('sails-mongo'),
 config={
 adapters:{default:mongoAdapter,mongo:mongoAdapter},
 connections:{
 localhostMongo:{
 adapter: 'mongo',host: 'localhost',port: 27017,database: 'test'
 }}};
 orm.loadCollection(Waterline.Collection.extend({
 identity: 'foo',
 connection: 'localhostMongo',
 attributes: {name: 'string'}
 }));
 function setupFoo(Foo){
 Foo.create({name:'Test Foo'}).then(function(foo){
 Foo.findOne().where({id:foo._id}).then(function(foo){
 if(!foo) console.log(
 'Waterline returns undefined when findOne returns nothing.');
 console.log('Got foo from database, %s.',JSON.stringify(foo,null,2));
 process.exit(0);
 });
 });
 }
 orm.initialize(config,function(err,models){
 if(err) return console.log(err);
 setupFoo(models.collections.foo);
 });
  • 6. Setup Results /usr/local/bin/node mongoose.js Got foo from database, { "_id": "558646750d141363a10539ee", "name": "Test Foo", "__v": 0 }. Process finished with exit code 0 /usr/local/bin/node waterline.js Got foo from database, { "name": "Test Foo", "createdAt": "2015-06-21T05:07:35.012Z", "updatedAt": "2015-06-21T05:07:35.012Z", "id": "5586469768455964a130adf4" }. Process finished with exit code 0
  • 7. Round 1: Setup Mongoose • Fast to setup • Uses callbacks natively • Thin wrapper for mongodb driver • Provides __v property for document versioning Waterline • Slightly more configuration • Uses promises natively • Abstracts data store from document definition • Provides created & modified timestamps
  • 8. Mongoose Constraints Foo=mongoose.model('Foo',{name:{type:String,required:true}});
 … function testConstraints(){
 var foo=new Foo({});
 foo.save(function(err){
 console.log(err);
 process.exit(1);
 });
 }
 … db.once('open', function () {
 testConstraints();
 });
  • 9. /usr/local/bin/node mongoose.js { [ValidationError: Foo validation failed] message: 'Foo validation failed', name: 'ValidationError', errors: { name: { [ValidatorError: Path `name` is required.] properties: [Object], message: 'Path `name` is required.', name: 'ValidatorError', kind: 'required', path: 'name', value: undefined } } } Process finished with exit code 1
  • 10. Waterline Constraints orm.loadCollection(Waterline.Collection.extend({
 identity: 'foo',
 connection: 'localhostMongo',
 attributes: {name:{type:'string',required:true}}
 }));
 … function testConstraints(Foo){
 Foo.create({}).catch(function(err){
 console.log(err);
 process.exit(1);
 });
 }
 orm.initialize(config,function(err,models){
 if(err) return console.log(err);
 testConstraints(models.collections.foo);
 });
  • 11. /usr/local/bin/node waterline.js Error (E_VALIDATION) :: 1 attribute is invalid at WLValidationError.WLError (techdt.la-mvw/node_modules/waterline/ lib/waterline/error/WLError.js:26:15) … Invalid attributes sent to foo: • name • `undefined` should be a string (instead of "null", which is a object) • "required" validation rule failed for input: null Process finished with exit code 1
  • 12. Round 2: Constraints Mongoose • Flexible constraints to handle most situations • Easy to setup • Somewhat hard to read validation error messages • Does not provide stack information Waterline • Flexible constraints to handle most situations • Easy to setup • Easy to read validation error messages • Provides stack information to help debugging
  • 13. Mongoose Visibility [1] Foo=mongoose.model('Foo',{
 name:{type:String,required:true},
 secret:{type:String,select:false}
 });
 … function testSecret(){
 var foo=new Foo({name:'Test Foo',secret:'123456'});
 foo.save(function(err,foo){
 if(err) return console.log(err);
 console.log( 'Saved foo to database, %s.',JSON.stringify(foo,null,2));
 Foo.findOne({_id:foo._id})
 .exec(function(err,foo){
 if(err) return console.log(err);
 if(!foo) console.log(
 'Mongoose returns undefined when findOne returns nothing.');
 console.log( 'Got foo from database, %s.',JSON.stringify(foo,null,2));
 process.exit(0);
 });
 })
 }
  • 14. /usr/local/bin/node mongoose.js Saved foo to database, { "__v": 0, "name": "Test Foo", "secret": "123456", "_id": "55864fdf4e5d5e94a1af5a14" }. Got foo from database, { "_id": "55864fdf4e5d5e94a1af5a14", "name": "Test Foo", "__v": 0 }. Process finished with exit code 0
  • 15. Mongoose Visibility [2] FooSchema=new mongoose.Schema({
 name:{type:String,required:true},
 secret:{type:String,select:false}
 },{toJSON:{transform: function (doc,ret) {delete ret.secret;}}}
 ),
 Foo=mongoose.model('Foo',FooSchema); /usr/local/bin/node mongoose.js Saved foo to database, { "__v": 0, "name": "Test Foo", "_id": "558654d2945f15a1a1a2d840" }. Got foo from database, { "_id": "558654d2945f15a1a1a2d840", "name": "Test Foo", "__v": 0 }. Process finished with exit code 0
  • 16. Waterline Visibility orm.loadCollection(Waterline.Collection.extend({
 identity: 'foo',
 connection: 'localhostMongo',
 attributes: {
 name:{type:'string',required:true},
 secret:{type:'string'},
 toJSON: function() {
 var foo= this.toObject();
 delete foo.secret;
 return foo;
 }
 }
 })); … function testSecret(Foo){
 Foo.create({name:'Test Foo',secret:123456}).then(function(foo){
 console.log( 'Saved foo to database, %s.',JSON.stringify(foo,null,2));
 })
 }
  • 17. /usr/local/bin/node waterline.js Saved foo to database, { "name": "Test Foo", "createdAt": "2015-06-21T06:30:44.374Z", "updatedAt": "2015-06-21T06:30:44.374Z", "id": "55865a146954cbb4a16fe33e" }.
  • 18. Round 3: Visibility Mongoose • Two methods to hide document properties • One doesn’t work in all cases • The other is a bit tough to configure Waterline • One method to hide document properties • Works in all cases • Simple to configure
  • 19. Mongoose Associations BarSchema=new mongoose.Schema({
 name:String,foo:{type:mongoose.Schema.Types.ObjectId,ref:'Foo'}
 }),
 Bar=mongoose.model('Bar',BarSchema);
 … function testAssociations(){
 var foo=new Foo({name:'Test Foo'});
 foo.save(function(err,foo){
 if(err) return console.log(err);
 var bar=new Bar({name:'Test Bar',foo:foo});
 bar.save(function(err,bar){
 if(err) return console.log(err);
 Bar.findOne({_id:bar._id},function(err,bar){
 console.log(
 'Got bar from database %s.',JSON.stringify(bar,null,2));
 bar.populate('foo',function(err,bar){
 if(err) return console.log(err);
 console.log(
 'Populated foo on bar %s.',JSON.stringify(bar,null,2));
 process.exit(0);
 });
 });
 });
 });
 }
  • 20. /usr/local/bin/node mongoose.js Got bar from database { "_id": "55865d0e96b702dba1cecc85", "name": "Test Bar", "foo": "55865d0d96b702dba1cecc84", "__v": 0 }. Populated foo from database { "_id": "55865d0e96b702dba1cecc85", "name": "Test Bar", "foo": { "_id": "55865d0d96b702dba1cecc84", "name": "Test Foo", "__v": 0 }, "__v": 0 }. Process finished with exit code 0
  • 21. Waterline Associations orm.loadCollection(Waterline.Collection.extend({
 identity: 'bar',
 connection: 'localhostMongo',
 attributes: {
 name:{type:'string',required:true},
 foo:{model:'foo'}
 }
 })); … function testAssociations(Foo,Bar){
 Foo.create({name:'Test Foo'}).then(function(foo){
 Bar.create({name:'Test Bar',foo:foo}).then(function(bar){
 console.log('Saved bar to database %s.',JSON.stringify(bar,0,2));
 Bar.findOne({id:bar.id}).populate('foo').then(function(bar){
 console.log('Populated foo on bar %s.',JSON.stringify(bar,0,2));
 process.exit(0);
 });
 });
 });
 }
  • 22. /usr/local/bin/node waterline.js Saved bar to database { "name": "Test Bar", "foo": "558660a765f025eba1fbb7af", "createdAt": "2015-06-21T06:58:47.079Z", "updatedAt": "2015-06-21T06:58:47.079Z", "id": "558660a765f025eba1fbb7b0" }. Populated foo on bar { "foo": { "name": "Test Foo", "createdAt": "2015-06-21T06:58:47.071Z", "updatedAt": "2015-06-21T06:58:47.071Z", "id": "558660a765f025eba1fbb7af" }, "name": "Test Bar", "createdAt": "2015-06-21T06:58:47.079Z", "updatedAt": "2015-06-21T06:58:47.079Z", "id": "558660a765f025eba1fbb7b0" }. Process finished with exit code 0
  • 23. Round 4: Associations Mongoose • Easy to setup document associations • Can call populate on find, or on a document • Associated documents may or may not be populated Waterline • Easy to setup document associations • Associated documents may live in other databases • Can only call populate on find • Associated documents only populated when requested
  • 24. Wrap Up Mongoose • Mongo ORM for JavaScript • Has some rough edges • Only option for highly concurrent document updates • Consistently more code to do the same things Waterline • JavaScript ORM for many popular databases • More modern, today JavaScript framework • Less rough edges • Does not support document isolation