Socket
Socket
Sign inDemoInstall

mongoose

Package Overview
Dependencies
Maintainers
4
Versions
888
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.7.4 to 1.8.0

8

History.md
1.8.0 / 2011-08-04
===================
* fixed; can now use $all with String and Number
* fixed; can query subdoc array with $ne: null
* fixed; instance.subdocs#id now works with custom _ids
* fixed; do not apply setters when doc returned from db (change in bad behavior)
1.7.4 / 2011-07-25

@@ -3,0 +11,0 @@ ===================

9

lib/mongoose/document.js

@@ -99,4 +99,7 @@

/**
* Inits (hydrates) the document.
* Inits (hydrates) the document without setters.
*
* Called internally after a document is returned
* from mongodb.
*
* @param {Object} document returned by mongo

@@ -131,3 +134,3 @@ * @api private

self.try(function(){
doc[i] = schema.applySetters(schema.cast(obj[i], self), self);
doc[i] = schema.cast(obj[i], self);
});

@@ -260,3 +263,3 @@ } else {

this.try(function(){
val = schema.applySetters(schema.cast(val, self), self);
val = schema.applySetters(schema.cast(val, self, true), self);
})) {

@@ -263,0 +266,0 @@

@@ -292,3 +292,3 @@

exports.version = '1.7.4';
exports.version = '1.8.0';

@@ -295,0 +295,0 @@ /**

@@ -202,6 +202,2 @@ var utils = require('./utils')

if ('$ne' === $cond && null === $cond) {
continue;
}
if ('$exists' === $cond) {

@@ -208,0 +204,0 @@ if ('boolean' !== typeof nested) {

@@ -138,3 +138,3 @@ /**

if (method) return method.call(proto, val);
return val.toObject ? val.toObject() : val;
return val != null && val.toObject ? val.toObject() : val;
}

@@ -141,0 +141,0 @@ }

@@ -68,3 +68,3 @@

if (err) return fn(err);
var count = array.length

@@ -98,12 +98,16 @@ , error = false;

DocumentArray.prototype.cast = function (value, doc) {
if (Array.isArray(value)){
DocumentArray.prototype.cast = function (value, doc, useSet) {
if (Array.isArray(value)) {
if (!(value instanceof MongooseDocumentArray))
value = new MongooseDocumentArray(value, this.path, doc);
for (var i = 0, l = value.length; i < l; i++)
if (!(value[i] instanceof Subdocument)){
for (var i = 0, l = value.length; i < l; i++) {
if (!(value[i] instanceof Subdocument)) {
var doc = new this.caster(null, value);
value[i] = doc.init(value[i].doc || value[i]);
value[i] = useSet
? doc.set (value[i].doc || value[i])
: doc.init(value[i].doc || value[i]);
}
}

@@ -110,0 +114,0 @@ return value;

@@ -108,11 +108,13 @@

SchemaNumber.prototype.$conditionalHandlers = {
'$lt': handleSingle
'$lt' : handleSingle
, '$lte': handleSingle
, '$gt': handleSingle
, '$gt' : handleSingle
, '$gte': handleSingle
, '$ne': handleSingle
, '$in': handleArray
, '$ne' : handleSingle
, '$in' : handleArray
, '$nin': handleArray
, '$mod': handleArray
, '$all': handleArray
};
SchemaNumber.prototype.castForQuery = function ($conditional, val) {

@@ -119,0 +121,0 @@ var handler;

@@ -140,3 +140,3 @@

var self = this;
return val.map( function (m) {
return val.map(function (m) {
return self.castForQuery(m);

@@ -154,3 +154,5 @@ });

, '$lte': handleSingle
, '$all': handleArray
};
SchemaString.prototype.castForQuery = function ($conditional, val) {

@@ -157,0 +159,0 @@ var handler;

@@ -61,11 +61,4 @@

MongooseDocumentArray.prototype.id = function(id) {
try {
var casted = ObjectIdSchema.prototype.cast.call(null, id);
} catch (e) {
// cast error
return null;
}
for (var i = 0, l = this.length; i < l; i++) {
if (ObjectId.toString(casted) == ObjectId.toString(this[i].get('_id')))
if (id == this[i].get('_id').toString())
return this[i];

@@ -72,0 +65,0 @@ }

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

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

@@ -954,17 +954,34 @@

, Mod = db.model('Mod', 'mods_' + random());
Mod.create({num: 1}, function (err, one) {
Mod.create({num: 1}, {num: 2, str: 'two'}, function (err, one, two) {
should.strictEqual(err, null);
Mod.create({num: 2}, function (err, two) {
should.strictEqual(err, null);
Mod.create({num: 3}, function (err, three) {
var pending = 2;
test1();
test2();
function test1 () {
Mod.find({$or: [{num: 1}, {num: 2}]}, function (err, found) {
done();
should.strictEqual(err, null);
Mod.find({$or: [{num: 1}, {num: 2}]}, function (err, found) {
should.strictEqual(err, null);
found.should.have.length(2);
found[0]._id.should.eql(one._id);
found[1]._id.should.eql(two._id);
db.close();
});
found.should.have.length(2);
found[0]._id.should.eql(one._id);
found[1]._id.should.eql(two._id);
});
});
}
function test2 () {
Mod.find({ $or: [{ str: 'two'}, {str:'three'}] }, function (err, found) {
if (err) console.error(err);
done();
should.strictEqual(err, null);
found.should.have.length(1);
found[0]._id.should.eql(two._id);
});
}
function done () {
if (--pending) return;
db.close();
}
});

@@ -1047,9 +1064,15 @@ },

BlogPostB.create({numbers: [-1,-2,-3,-4]}, function (err, whereoutZero) {
BlogPostB.create(
{numbers: [-1,-2,-3,-4], meta: { visitors: 4 }}
, {numbers: [0,-1,-2,-3,-4]}
, function (err, whereoutZero, whereZero) {
should.strictEqual(err, null);
BlogPostB.create({numbers: [0,-1,-2,-3,-4]}, function (err, whereZero) {
BlogPostB.find({numbers: {$all: [-1, -2, -3, -4]}}, function (err, found) {
should.strictEqual(err, null);
BlogPostB.find({numbers: {$all: [-1, -2, -3, -4]}}, function (err, found) {
found.should.have.length(2);
BlogPostB.find({'meta.visitors': {$all: [4] }}, function (err, found) {
should.strictEqual(err, null);
found.should.have.length(2);
found.should.have.length(1);
found[0]._id.should.eql(whereoutZero._id);
BlogPostB.find({numbers: {$all: [0, -1]}}, function (err, found) {

@@ -1059,2 +1082,3 @@ db.close();

found.should.have.length(1);
found[0]._id.should.eql(whereZero._id);
});

@@ -1070,3 +1094,3 @@ });

var post = new BlogPostB();
var post = new BlogPostB({ title: "Aristocats" });

@@ -1083,10 +1107,25 @@ post.tags.push('onex');

BlogPostB.find({tags: { '$all': [/^onex/i]}}, function (err, docs) {
BlogPostB.find({ title: { '$all': ['Aristocats']}}, function (err, docs) {
should.strictEqual(err, null);
docs.length.should.equal(1);
BlogPostB.findOne({tags: { '$all': /^two/ }}, function (err, doc) {
db.close();
BlogPostB.find({ title: { '$all': [/^Aristocats/]}}, function (err, docs) {
should.strictEqual(err, null);
doc.id.should.eql(post.id);
docs.length.should.equal(1);
BlogPostB.find({tags: { '$all': ['onex','twox','threex']}}, function (err, docs) {
should.strictEqual(err, null);
docs.length.should.equal(1);
BlogPostB.find({tags: { '$all': [/^onex/i]}}, function (err, docs) {
should.strictEqual(err, null);
docs.length.should.equal(1);
BlogPostB.findOne({tags: { '$all': /^two/ }}, function (err, doc) {
db.close();
should.strictEqual(err, null);
doc.id.should.eql(post.id);
});
});
});
});

@@ -1093,0 +1132,0 @@ });

@@ -631,2 +631,17 @@

'Querying a subdocument array with $ne: null should not throw': function () {
var query = new Query();
var db = start();
var Product = db.model('Product');
var Comment = db.model('Comment');
db.close();
var params = {
comments: { $ne: null }
};
query.cast(Product, params);
should.strictEqual(params.comments.$ne, null);
},
'Query#find should not cast single value to array for schematype of Array': function () {

@@ -633,0 +648,0 @@ var query = new Query();

@@ -8,5 +8,37 @@

, MongooseArray = mongoose.Types.Array
, MongooseDocumentArray = mongoose.Types.DocumentArray;
, MongooseDocumentArray = mongoose.Types.DocumentArray
, EmbeddedDocument = require('mongoose/types/document')
, DocumentArray = require('mongoose/types/documentarray')
, Schema = mongoose.Schema
/**
* Setup.
*/
function TestDoc (schema) {
var Subdocument = function () {
EmbeddedDocument.call(this, {}, new DocumentArray);
};
/**
* Inherits from EmbeddedDocument.
*/
Subdocument.prototype.__proto__ = EmbeddedDocument.prototype;
/**
* Set schema.
*/
var SubSchema = new Schema({
title: { type: String }
});
Subdocument.prototype.schema = schema || SubSchema;
return Subdocument;
}
/**
* Test.

@@ -30,4 +62,50 @@ */

Object.keys(b).length.should.equal(4);
},
'#id': function () {
var Subdocument = TestDoc();
var sub1 = new Subdocument();
sub1.title = 'Hello again to all my friends';
var id = sub1.id;
var a = new MongooseDocumentArray([sub1]);
a.id(id).title.should.equal('Hello again to all my friends');
a.id(sub1._id).title.should.equal('Hello again to all my friends');
// test with custom string _id
var Custom = new Schema({
title: { type: String }
, _id: { type: String, required: true }
});
var Subdocument = TestDoc(Custom);
var sub2 = new Subdocument();
sub2.title = 'together we can play some rock-n-roll';
sub2._id = 'a25';
var id2 = sub2.id;
var a = new MongooseDocumentArray([sub2]);
a.id(id2).title.should.equal('together we can play some rock-n-roll');
a.id(sub2._id).title.should.equal('together we can play some rock-n-roll');
// test with custom number _id
var CustNumber = new Schema({
title: { type: String }
, _id: { type: Number, required: true }
});
var Subdocument = TestDoc(CustNumber);
var sub3 = new Subdocument();
sub3.title = 'rock-n-roll';
sub3._id = 1995;
var id3 = sub3.id;
var a = new MongooseDocumentArray([sub3]);
a.id(id3).title.should.equal('rock-n-roll');
a.id(sub3._id).title.should.equal('rock-n-roll');
}
};

Sorry, the diff of this file is too big to display

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