Skip to content

Commit

Permalink
lint examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianMurphy committed Jul 23, 2015
1 parent 0c93a4a commit ea845c6
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 24 deletions.
7 changes: 5 additions & 2 deletions examples/aggregate/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var data = [
likes : ['books', 'cats', 'dogs']},
{ name : 'alucard', age : 1000, birthday : new Date().setFullYear((new
Date().getFullYear() - 1000)), gender : "Male",
likes : ['glasses', 'wine', 'the night']},
likes : ['glasses', 'wine', 'the night']}
];


Expand All @@ -36,7 +36,10 @@ mongoose.connect('mongodb://localhost/persons', function (err) {
async.each(data, function (item, cb) {
Person.create(item, cb);
}, function (err) {

if (err) {
// handle error
}

// run an aggregate query that will get all of the people who like a given
// item. To see the full documentation on ways to use the aggregate
// framework, see http://docs.mongodb.org/manual/core/aggregation/
Expand Down
3 changes: 1 addition & 2 deletions examples/express/connection-sharing/modelA.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

var Schema = require('../../../lib').Schema;
var mySchema = Schema({ name: String });

// db is global
/* global db */
module.exports = db.model('MyModel', mySchema);
9 changes: 6 additions & 3 deletions examples/geospatial/geospatial.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var data = [
likes : ['books', 'cats', 'dogs'], loc : [6, 6]},
{ name : 'alucard', age : 1000, birthday : new Date().setFullYear((new
Date().getFullYear() - 1000)), gender : "Male",
likes : ['glasses', 'wine', 'the night'], loc : [10, 10]},
likes : ['glasses', 'wine', 'the night'], loc : [10, 10]}
];


Expand All @@ -36,7 +36,10 @@ mongoose.connect('mongodb://localhost/persons', function (err) {
async.each(data, function (item, cb) {
Person.create(item, cb);
}, function (err) {

if (err) {
// handler error
}

// let's find the closest person to bob
Person.find({ name : 'bob' }, function (err, res) {
if (err) throw err;
Expand All @@ -45,7 +48,7 @@ mongoose.connect('mongodb://localhost/persons', function (err) {
if (err) throw err;

console.log("%s is closest to %s", res[0].name, closest);


// we can also just query straight off of the model. For more
// information about geospatial queries and indexes, see
Expand Down
9 changes: 6 additions & 3 deletions examples/lean/lean.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var data = [
likes : ['books', 'cats', 'dogs']},
{ name : 'alucard', age : 1000, birthday : new Date().setFullYear((new
Date().getFullYear() - 1000)), gender : "Male",
likes : ['glasses', 'wine', 'the night']},
likes : ['glasses', 'wine', 'the night']}
];


Expand All @@ -36,11 +36,14 @@ mongoose.connect('mongodb://localhost/persons', function (err) {
async.each(data, function (item, cb) {
Person.create(item, cb);
}, function (err) {

if (err) {
// handle error
}

// lean queries return just plain javascript objects, not
// MongooseDocuments. This makes them good for high performance read
// situations

// when using .lean() the default is true, but you can explicitly set the
// value by passing in a boolean value. IE. .lean(false)
var q = Person.find({ age : { $lt : 1000 }}).sort('age').limit(2).lean();
Expand Down
11 changes: 7 additions & 4 deletions examples/mapreduce/mapreduce.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// import async to make control flow simplier
var async = require('async');

Expand All @@ -20,7 +19,7 @@ var data = [
{ name : 'lilly', age : 26, birthday : new Date().setFullYear((new
Date().getFullYear() - 26)), gender : "Female" },
{ name : 'alucard', age : 1000, birthday : new Date().setFullYear((new
Date().getFullYear() - 1000)), gender : "Male" },
Date().getFullYear() - 1000)), gender : "Male" }
];


Expand All @@ -31,7 +30,10 @@ mongoose.connect('mongodb://localhost/persons', function (err) {
async.each(data, function (item, cb) {
Person.create(item, cb);
}, function (err) {

if (err) {
// handle error
}

// alright, simple map reduce example. We will find the total ages of each
// gender

Expand All @@ -40,7 +42,8 @@ mongoose.connect('mongodb://localhost/persons', function (err) {

o.map = function () {
// in this function, 'this' refers to the current document being
// processed. Return the (gender, age) tuple using emit()
// processed. Return the (gender, age) tuple using
/* global emit */
emit(this.gender, this.age);
};

Expand Down
4 changes: 2 additions & 2 deletions examples/population/population-across-three-collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mongoose.connection.on('open', function() {
friends: [userIds[0], userIds[1], userIds[2]]
});

User.create(users, function(err, docs) {
User.create(users, function(err) {
assert.ifError(err);

var blogposts = [];
Expand All @@ -91,7 +91,7 @@ mongoose.connection.on('open', function() {
author: userIds[2]
})

BlogPost.create(blogposts, function(err, docs) {
BlogPost.create(blogposts, function(err) {
assert.ifError(err);

/**
Expand Down
9 changes: 6 additions & 3 deletions examples/promises/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var data = [
{ name : 'lilly', age : 26, birthday : new Date().setFullYear((new
Date().getFullYear() - 26)) },
{ name : 'alucard', age : 1000, birthday : new Date().setFullYear((new
Date().getFullYear() - 1000)) },
Date().getFullYear() - 1000)) }
];


Expand All @@ -31,7 +31,10 @@ mongoose.connect('mongodb://localhost/persons', function (err) {
async.each(data, function (item, cb) {
Person.create(item, cb);
}, function (err) {

if (err) {
// handle error
}

// create a promise (get one from the query builder)
var prom = Person.find({age : { $lt : 1000 }}).exec();

Expand All @@ -54,7 +57,7 @@ mongoose.connect('mongodb://localhost/persons', function (err) {
var ids = people.map(function (p) {
return p._id;
});

// return the next promise
return Person.find({ _id : { $nin : ids }}).exec();
}).then(function (oldest) {
Expand Down
6 changes: 3 additions & 3 deletions examples/querybuilder/querybuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var data = [
{ name : 'lilly', age : 26, birthday : new Date().setFullYear((new
Date().getFullYear() - 26)) },
{ name : 'alucard', age : 1000, birthday : new Date().setFullYear((new
Date().getFullYear() - 1000)) },
Date().getFullYear() - 1000)) }
];


Expand All @@ -40,7 +40,7 @@ mongoose.connect('mongodb://localhost/persons', function (err) {
// this allows you to continue applying modifiers to it
query.sort('birthday');
query.select('name');

// you can chain them together as well
// a full list of methods can be found:
// http://mongoosejs.com/docs/api.html#query-js
Expand All @@ -54,7 +54,7 @@ mongoose.connect('mongodb://localhost/persons', function (err) {

cleanup();
});

});
});

Expand Down
5 changes: 4 additions & 1 deletion examples/replicasets/replica-sets.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var data = [
{ name : 'lilly', age : 26, birthday : new Date().setFullYear((new
Date().getFullYear() - 26)) },
{ name : 'alucard', age : 1000, birthday : new Date().setFullYear((new
Date().getFullYear() - 1000)) },
Date().getFullYear() - 1000)) }
];


Expand All @@ -36,6 +36,9 @@ mongoose.connect('mongodb://localhost:27018/persons,localhost:27019,localhost:27
async.each(data, function (item, cb) {
Person.create(item, cb);
}, function (err) {
if (err) {
// handle error
}

// create and delete some data
var prom = Person.find({age : { $lt : 1000 }}).exec();
Expand Down
3 changes: 2 additions & 1 deletion examples/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ BlogPost.path('date')
*/

BlogPost.pre('save', function(next, done){
/* global emailAuthor */
emailAuthor(done); // some async function
next();
});
Expand Down Expand Up @@ -90,7 +91,7 @@ function slugGenerator (options){
return v;
});
};
};
}

BlogPost.plugin(slugGenerator());

Expand Down

0 comments on commit ea845c6

Please sign in to comment.