Comparing version
2.2.2 / 2011-09-28 | ||
================== | ||
* added; $regex support to String [davidandrewcope] | ||
* added; support for other contexts like repl etc (#535) | ||
* fixed; clear modified state properly after saving | ||
* added; $addToSet support to Array | ||
2.2.1 / 2011-09-22 | ||
@@ -3,0 +12,0 @@ ================== |
@@ -173,3 +173,3 @@ | ||
if (!schema && obj[i] && obj[i].constructor == Object) { | ||
if (!schema && obj[i] && 'Object' === obj[i].constructor.name) { | ||
// assume nested object | ||
@@ -260,3 +260,3 @@ doc[i] = {}; | ||
&& null !== path[key] | ||
&& Object == path[key].constructor) { | ||
&& 'Object' == path[key].constructor.name) { | ||
this.set(path[key], prefix + key); | ||
@@ -330,3 +330,3 @@ } else if (undefined !== path[key]) { | ||
} else { | ||
if (obj[parts[i]] && obj[parts[i]].constructor === Object) { | ||
if (obj[parts[i]] && 'Object' === obj[parts[i]].constructor.name) { | ||
obj = obj[parts[i]]; | ||
@@ -644,3 +644,3 @@ } else if (obj[parts[i]] && Array.isArray(obj[parts[i]])) { | ||
define(key | ||
, ((limb.constructor == Object | ||
, (('Object' === limb.constructor.name | ||
&& Object.keys(limb).length) | ||
@@ -647,0 +647,0 @@ && (!limb.type || limb.type.type) |
@@ -276,3 +276,3 @@ | ||
exports.version = '2.2.1'; | ||
exports.version = '2.2.2'; | ||
@@ -279,0 +279,0 @@ /** |
@@ -190,3 +190,3 @@ | ||
if (!schema && obj[i] && obj[i].constructor == Object) { | ||
if (!schema && obj[i] && 'Object' === obj[i].constructor.name) { | ||
// assume nested object | ||
@@ -243,14 +243,5 @@ init(obj[i], path + '.', next); | ||
function handleSave (promise, self, insert) { | ||
function handleSave (promise, self) { | ||
return function handleSave (err) { | ||
if (err) { | ||
if (insert) { | ||
// reset isNew | ||
self.isNew = true; | ||
self.emit('isNew', true); // embedded docs | ||
} | ||
return promise.error(err); | ||
} | ||
self._reset(); | ||
if (err) return promise.error(err); | ||
self.emit('save', self); | ||
@@ -273,5 +264,4 @@ promise.complete(self); | ||
var promise = new Promise(fn) | ||
, complete = handleSave(promise, this) | ||
, options = {} | ||
, self = this | ||
, complete | ||
@@ -284,4 +274,4 @@ if (this.options.safe) { | ||
// send entire doc | ||
complete = handleSave(promise, this, true); | ||
this.collection.insert(this.toObject({ depopulate: 1 }), options, complete); | ||
this._reset(); | ||
this.isNew = false; | ||
@@ -291,4 +281,4 @@ this.emit('isNew', false); | ||
} else { | ||
complete = handleSave(promise, this); | ||
var delta = this._delta(); | ||
this._reset(); | ||
@@ -301,3 +291,2 @@ if (delta) { | ||
} | ||
}; | ||
@@ -367,3 +356,3 @@ | ||
if (op === '$pull' || op === '$push') { | ||
if (val.constructor !== Object) { | ||
if ('Object' !== val.constructor.name) { | ||
if (Array.isArray(val)) val = [val]; | ||
@@ -370,0 +359,0 @@ // TODO Should we place pull and push casting into the pull and push methods? |
@@ -117,3 +117,3 @@ /** | ||
merge(this._conditions, criteria.toObject()); | ||
} else if (criteria && criteria.constructor === Object) { | ||
} else if (criteria && 'Object' === criteria.constructor.name) { | ||
merge(this._conditions, criteria); | ||
@@ -210,3 +210,3 @@ } | ||
continue; | ||
} else if (val.constructor == Object) { | ||
} else if ('Object' === val.constructor.name) { | ||
@@ -319,3 +319,3 @@ any$conditionals = Object.keys(val).some(function (k) { | ||
// $lt, $lte, $gt, $gte can be used on Numbers or Dates | ||
'gt gte lt lte ne in nin all size maxDistance'.split(' ').forEach( function ($conditional) { | ||
'gt gte lt lte ne in nin all regex size maxDistance'.split(' ').forEach( function ($conditional) { | ||
Query.prototype['$' + $conditional] = | ||
@@ -374,3 +374,3 @@ Query.prototype[$conditional] = function (path, val) { | ||
var block; | ||
if (path.constructor === Object) { | ||
if ('Object' === path.constructor.name) { | ||
criteria = path; | ||
@@ -381,3 +381,3 @@ path = this._currPath; | ||
path = this._currPath; | ||
} else if (criteria.constructor === Object) { | ||
} else if ('Object' === criteria.constructor.name) { | ||
} else if ('function' === typeof criteria) { | ||
@@ -465,3 +465,3 @@ block = criteria; | ||
if (!arg0) return this; | ||
if (arg0.constructor === Object || Array.isArray(arg0)) { | ||
if ('Object' === arg0.constructor.name || Array.isArray(arg0)) { | ||
this._applyFields(arg0); | ||
@@ -596,3 +596,3 @@ } else if (arguments.length === 1 && typeof arg0 === 'string') { | ||
}, {}); | ||
} else if (fields.constructor === Object) { | ||
} else if ('Object' === fields.constructor.name) { | ||
$fields = fields; | ||
@@ -672,3 +672,3 @@ } else { | ||
}); | ||
} else if (v.constructor === Object) { | ||
} else if ('Object' === v.constructor.name) { | ||
// must keep object keys in order so don't use Object.keys() | ||
@@ -1005,3 +1005,3 @@ for (k in v) { | ||
} else { | ||
if (Object !== val.constructor) { | ||
if ('Object' !== val.constructor.name) { | ||
var msg = 'Invalid atomic update value for ' + path + '. ' | ||
@@ -1008,0 +1008,0 @@ + 'Expected an object, received ' + typeof val; |
@@ -405,3 +405,3 @@ | ||
field[prefix + i] = '2d' === index ? index : 1; | ||
indexes.push([field, index.constructor == Object ? index : {} ]); | ||
indexes.push([field, 'Object' === index.constructor.name ? index : {} ]); | ||
} | ||
@@ -408,0 +408,0 @@ } |
@@ -154,2 +154,3 @@ | ||
, '$all': handleArray | ||
, '$regex': handleSingle | ||
}; | ||
@@ -156,0 +157,0 @@ |
@@ -86,3 +86,3 @@ | ||
SchemaType.prototype.unique = function (bool) { | ||
if (!this._index || Object !== this._index.constructor) { | ||
if (!this._index || 'Object' !== this._index.constructor.name) { | ||
this._index = {}; | ||
@@ -103,3 +103,3 @@ } | ||
SchemaType.prototype.sparse = function (bool) { | ||
if (!this._index || Object !== this._index.constructor) { | ||
if (!this._index || 'Object' !== this._index.constructor.name) { | ||
this._index = {}; | ||
@@ -106,0 +106,0 @@ } |
@@ -288,2 +288,3 @@ | ||
* Splices the array. | ||
* @api public | ||
*/ | ||
@@ -298,2 +299,26 @@ | ||
/** | ||
* Adds values to the array if not already present. | ||
* @api public | ||
*/ | ||
MongooseArray.prototype.$addToSet = | ||
MongooseArray.prototype.addToSet = function addToSet () { | ||
var values = Array.prototype.map.call(arguments, this._cast, this) | ||
, added = []; | ||
values.forEach(function (v) { | ||
var found = v instanceof EmbeddedDocument | ||
? this.some(function(doc){ return doc.equals(v) }) | ||
: ~this.indexOf(v) | ||
if (!found) { | ||
this.push(v); | ||
added.push(v); | ||
} | ||
}, this); | ||
return added; | ||
}; | ||
/** | ||
* Returns an Array | ||
@@ -300,0 +325,0 @@ * |
@@ -218,9 +218,9 @@ /** | ||
if (obj.constructor == Object) | ||
if ('Object' === obj.constructor.name) | ||
return cloneObject(obj, options); | ||
if (obj.constructor == Date || obj.constructor == Function) | ||
if ('Date' === obj.constructor.name || 'Function' === obj.constructor.name) | ||
return new obj.constructor(+obj); | ||
if (obj.constructor == RegExp) | ||
if ('RegExp' === obj.constructor.name) | ||
return new RegExp(obj.source); | ||
@@ -227,0 +227,0 @@ |
{ | ||
"name": "mongoose" | ||
, "description": "Mongoose MongoDB ORM" | ||
, "version": "2.2.1" | ||
, "version": "2.2.2" | ||
, "author": "Guillermo Rauch <guillermo@learnboost.com>" | ||
@@ -6,0 +6,0 @@ , "keywords": ["mongodb", "mongoose", "orm", "data", "datastore", "nosql"] |
@@ -840,3 +840,3 @@ | ||
'test querying via $which where a string': function () { | ||
'test querying via $where a string': function () { | ||
var db = start() | ||
@@ -857,3 +857,3 @@ , BlogPostB = db.model('BlogPostB', collection); | ||
'test querying via $which where a function': function () { | ||
'test querying via $where a function': function () { | ||
var db = start() | ||
@@ -1137,3 +1137,26 @@ , BlogPostB = db.model('BlogPostB', collection); | ||
found._id.should.eql(created._id); | ||
db.close(); | ||
var reg = '^Next to Normal$'; | ||
BlogPostB.find({ title: { $regex: reg }}, function (err, found) { | ||
should.strictEqual(err, null); | ||
found.length.should.equal(1); | ||
found[0]._id.should.eql(created._id); | ||
BlogPostB.findOne({ title: { $regex: reg }}, function (err, found) { | ||
should.strictEqual(err, null); | ||
found._id.should.eql(created._id); | ||
BlogPostB.where('title').$regex(reg).findOne(function (err, found) { | ||
should.strictEqual(err, null); | ||
found._id.should.eql(created._id); | ||
BlogPostB.where('title').$regex(/^Next/).findOne(function (err, found) { | ||
db.close(); | ||
should.strictEqual(err, null); | ||
found._id.should.eql(created._id); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -1140,0 +1163,0 @@ }); |
@@ -148,3 +148,85 @@ | ||
}); | ||
}, | ||
'#addToSet': function () { | ||
var db = start() | ||
, e = new Schema({ name: String, arr: [] }) | ||
, schema = new Schema({ | ||
num: [Number] | ||
, str: [String] | ||
, doc: [e] | ||
, date: [Date] | ||
, id: [Schema.ObjectId] | ||
}); | ||
var M = db.model('testAddToSet', schema); | ||
var m = new M; | ||
m.num.push(1,2,3); | ||
m.str.push('one','two','tres'); | ||
m.doc.push({ name: 'Dubstep', arr: [1] }, { name: 'Polka', arr: [{ x: 3 }]}); | ||
var d1 = new Date; | ||
var d2 = new Date( d1 + 60000); | ||
var d3 = new Date( d1 + 30000); | ||
m.date.push(d1, d2); | ||
var id1 = new mongoose.Types.ObjectId; | ||
var id2 = new mongoose.Types.ObjectId; | ||
var id3 = new mongoose.Types.ObjectId; | ||
m.id.push(id1, id2); | ||
m.num.addToSet(3,4,5); | ||
m.num.length.should.equal(5); | ||
m.str.$addToSet('four', 'five', 'two'); | ||
m.str.length.should.equal(5); | ||
m.id.addToSet(id2, id3); | ||
m.id.length.should.equal(3); | ||
m.doc.$addToSet(m.doc[0]); | ||
m.doc.length.should.equal(2); | ||
m.doc.$addToSet({ name: 'Waltz', arr: [1] }, m.doc[0]); | ||
m.doc.length.should.equal(3); | ||
m.date.$addToSet(d1); | ||
m.date.length.should.equal(2); | ||
m.date.addToSet(d3); | ||
m.date.length.should.equal(3); | ||
m.save(function (err) { | ||
should.strictEqual(null, err); | ||
M.findById(m, function (err, m) { | ||
db.close(); | ||
should.strictEqual(null, err); | ||
m.num.length.should.equal(5); | ||
(~m.num.indexOf(1)).should.be.ok; | ||
(~m.num.indexOf(2)).should.be.ok; | ||
(~m.num.indexOf(3)).should.be.ok; | ||
(~m.num.indexOf(4)).should.be.ok; | ||
(~m.num.indexOf(5)).should.be.ok; | ||
m.str.length.should.equal(5); | ||
(~m.str.indexOf('one')).should.be.ok; | ||
(~m.str.indexOf('two')).should.be.ok; | ||
(~m.str.indexOf('tres')).should.be.ok; | ||
(~m.str.indexOf('four')).should.be.ok; | ||
(~m.str.indexOf('five')).should.be.ok; | ||
m.id.length.should.equal(3); | ||
(~m.id.indexOf(id1)).should.be.ok; | ||
(~m.id.indexOf(id2)).should.be.ok; | ||
(~m.id.indexOf(id3)).should.be.ok; | ||
m.date.length.should.equal(3); | ||
(~m.date.indexOf(d1.toString())).should.be.ok; | ||
(~m.date.indexOf(d2.toString())).should.be.ok; | ||
(~m.date.indexOf(d3.toString())).should.be.ok; | ||
m.doc.length.should.equal(3); | ||
m.doc.some(function(v){return v.name === 'Waltz'}).should.be.ok | ||
m.doc.some(function(v){return v.name === 'Dubstep'}).should.be.ok | ||
m.doc.some(function(v){return v.name === 'Polka'}).should.be.ok | ||
}); | ||
}); | ||
} | ||
}; |
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
16682
0.74%694458
-1.07%108
-0.92%