Socket
Socket
Sign inDemoInstall

mongoose

Package Overview
Dependencies
Maintainers
0
Versions
883
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

6

History.md
1.1.2 / 2011-03-03
==================
* Restored Query#exec and added notion of default operation [brian]
* Fixed ValidatorError messages [brian]
1.1.1 / 2011-03-01

@@ -3,0 +9,0 @@ ==================

3

lib/mongoose/error.js

@@ -9,4 +9,5 @@

function MongooseError (msg) {
Error.call(this, msg);
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
this.message = msg;
this.name = 'MongooseError';

@@ -13,0 +14,0 @@ };

@@ -284,3 +284,3 @@

exports.version = '1.1.1';
exports.version = '1.1.2';

@@ -287,0 +287,0 @@ /**

@@ -315,3 +315,3 @@

}
var query = new Query(conditions).bind(this);
var query = new Query(conditions).bind(this, 'remove');
if ('undefined' === typeof callback)

@@ -326,3 +326,3 @@ return query;

}
if (!query.model) query.bind(this);
if (!query.model) query.bind(this, 'remove');
return query.remove(callback);

@@ -362,3 +362,3 @@ };

var query = new Query(conditions, options).select(fields).bind(this);
var query = new Query(conditions, options).select(fields).bind(this, 'find');

@@ -378,3 +378,3 @@ if ('undefined' === typeof callback)

if (!query.model)
query.bind(this);
query.bind(this, 'find');
return query.find(callback);

@@ -427,3 +427,3 @@ };

var query = new Query(conditions, options).select(fields).bind(this);
var query = new Query(conditions, options).select(fields).bind(this, 'findOne');
if ('undefined' == typeof callback)

@@ -440,3 +440,3 @@ return query;

}
if (!query.model) query.bind(this);
if (!query.model) query.bind(this, 'findOne');
return query.findOne(callback);

@@ -454,3 +454,3 @@ };

Model.count = function (conditions, callback) {
var query = new Query(conditions).bind(this);
var query = new Query(conditions).bind(this, 'count');
if ('undefined' == typeof callback)

@@ -465,3 +465,3 @@ return query;

}
if (!query.model) query.bind(this);
if (!query.model) query.bind(this, 'count');
return query.count(callback);

@@ -488,3 +488,3 @@ };

Model.where = function (path, val) {
var q = new Query().bind(this);
var q = new Query().bind(this, 'find');
return q.where.apply(q, arguments);

@@ -505,3 +505,3 @@ };

Model.$where = function () {
var q = new Query().bind(this);
var q = new Query().bind(this, 'find');
return q.$where.apply(q, arguments);

@@ -577,3 +577,3 @@ };

}
var query = new Query(conditions, options).bind(this);
var query = new Query(conditions, options).bind(this, 'update', doc);
if ('undefined' == typeof callback)

@@ -588,3 +588,3 @@ return query;

}
if (!query.model) query.bind(this);
if (!query.model) query.bind(this, 'update');
return query.update(doc, callback);

@@ -591,0 +591,0 @@ };

@@ -25,9 +25,30 @@ var utils = require('./utils')

Query.prototype.bind = function (model) {
Query.prototype.bind = function (model, op, updateArg) {
var ret = Object.create(this);
ret.model = model;
ret.op = op;
if (op === 'update') this._updateArg = updateArg;
return ret;
};
Query.prototype.run =
Query.prototype.exec = function (op, callback) {
var args = arguments;
if ('function' === typeof op) {
callback = op;
if (this.op === 'update') {
return this[this.op](this._updateArg, callback);
}
return this[this.op](callback);
}
args = Array.prototype.slice.call(arguments, 1);
this.op = op;
if (op === 'update' && args.length === 1) {
args.unshift(this._updateArg);
}
this[op].apply(this, args);
};
Query.prototype.find = function (criteria, callback) {
this.op = 'find';
if ('function' === typeof criteria) {

@@ -550,2 +571,3 @@ callback = criteria;

Query.prototype.findOne = function (callback) {
this.op = 'findOne';
var model = this.model;

@@ -582,2 +604,3 @@ var options = this._optionsForExec(model);

Query.prototype.count = function (callback) {
this.op = 'count';
var model = this.model;

@@ -600,2 +623,4 @@ this.cast(model);

Query.prototype.update = function (doc, callback) {
this.op = 'update';
this._updateArg = doc;
var model = this.model

@@ -626,2 +651,3 @@ , options = this._optionsForExec(model);

Query.prototype.remove = function (callback) {
this.op = 'remove';
var model = this.model;

@@ -628,0 +654,0 @@ this.cast(model);

{
"name": "mongoose"
, "description": "Mongoose MongoDB ORM"
, "version": "1.1.1"
, "version": "1.1.2"
, "author": "Guillermo Rauch <guillermo@learnboost.com>"

@@ -6,0 +6,0 @@ , "keywords": ["mongodb", "mongoose", "orm", "data", "datastore", "nosql"]

@@ -607,2 +607,29 @@

'test validation with custom message': function () {
function validate (val) {
return val === 'abc';
}
mongoose.model('TestValidationMessage', new Schema({
simple: { type: String, validate: [validate, 'must be abc'] }
}));
var db = start()
, TestValidationMessage = db.model('TestValidationMessage');
var post = new TestValidationMessage();
post.set('simple', '');
post.save(function(err){
err.should.be.an.instanceof(MongooseError);
err.should.be.an.instanceof(ValidatorError);
err.message.should.equal('Validator "must be abc" failed for path simple');
post.set('simple', 'abc');
post.save(function(err){
should.strictEqual(err, null);
db.close();
});
});
},
'test required validation for undefined values': function () {

@@ -2192,2 +2219,110 @@ mongoose.model('TestUndefinedValidation', new Schema({

'test count querying via #run (aka #exec)': function () {
var db = start()
, BlogPost = db.model('BlogPost', collection);
BlogPost.create({title: 'interoperable count as promise'}, function (err, created) {
should.strictEqual(err, null);
var query = BlogPost.count({title: 'interoperable count as promise'});
query.exec(function (err, count) {
should.strictEqual(err, null);
count.should.equal(1);
db.close();
});
});
},
'test update querying via #run (aka #exec)': function () {
var db = start()
, BlogPost = db.model('BlogPost', collection);
BlogPost.create({title: 'interoperable update as promise'}, function (err, created) {
should.strictEqual(err, null);
var query = BlogPost.update({title: 'interoperable update as promise'}, {title: 'interoperable update as promise delta'});
query.exec(function (err) {
should.strictEqual(err, null);
BlogPost.count({title: 'interoperable update as promise delta'}, function (err, count) {
should.strictEqual(err, null);
count.should.equal(1);
db.close();
});
});
});
},
'test findOne querying via #run (aka #exec)': function () {
var db = start()
, BlogPost = db.model('BlogPost', collection);
BlogPost.create({title: 'interoperable findOne as promise'}, function (err, created) {
should.strictEqual(err, null);
var query = BlogPost.findOne({title: 'interoperable findOne as promise'});
query.exec(function (err, found) {
should.strictEqual(err, null);
found._id.should.eql(created._id);
db.close();
});
});
},
'test find querying via #run (aka #exec)': function () {
var db = start()
, BlogPost = db.model('BlogPost', collection);
BlogPost.create(
{title: 'interoperable find as promise'}
, {title: 'interoperable find as promise'}
, function (err, createdOne, createdTwo) {
should.strictEqual(err, null);
var query = BlogPost.find({title: 'interoperable find as promise'});
query.exec(function (err, found) {
should.strictEqual(err, null);
found.should.have.length(2);
found[0]._id.should.eql(createdOne._id);
found[1]._id.should.eql(createdTwo._id);
db.close();
});
});
},
'test remove querying via #run (aka #exec)': function () {
var db = start()
, BlogPost = db.model('BlogPost', collection);
BlogPost.create(
{title: 'interoperable remove as promise'}
, function (err, createdOne, createdTwo) {
should.strictEqual(err, null);
var query = BlogPost.remove({title: 'interoperable remove as promise'});
query.exec(function (err) {
should.strictEqual(err, null);
BlogPost.count({title: 'interoperable remove as promise'}, function (err, count) {
db.close();
count.should.equal(0);
});
});
});
},
'test changing query at the last minute via #run(op, callback)': function () {
var db = start()
, BlogPost = db.model('BlogPost', collection);
BlogPost.create({title: 'interoperable ad-hoc as promise'}, function (err, created) {
should.strictEqual(err, null);
var query = BlogPost.count({title: 'interoperable ad-hoc as promise'});
query.exec('findOne', function (err, found) {
should.strictEqual(err, null);
found._id.should.eql(created._id);
db.close();
});
});
}
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc