Comparing version 1.3.2 to 1.3.3
1.3.3 / 2011-04-27 | ||
=================== | ||
* fixed; corrected query casting on nested mixed types | ||
1.3.2 / 2011-04-27 | ||
@@ -3,0 +8,0 @@ =================== |
@@ -292,3 +292,3 @@ | ||
exports.version = '1.3.2'; | ||
exports.version = '1.3.3'; | ||
@@ -295,0 +295,0 @@ /** |
@@ -108,4 +108,9 @@ var utils = require('./utils') | ||
, paths = Object.keys(obj) | ||
, i = paths.length, path, val, schematype, nested | ||
, any$conditionals, type; | ||
, i = paths.length | ||
, any$conditionals | ||
, schematype | ||
, nested | ||
, path | ||
, type | ||
, val; | ||
@@ -121,15 +126,23 @@ while (i--) { | ||
while (k--) { | ||
orComponentQuery = new Query(val[k]) | ||
orComponentQuery = new Query(val[k]); | ||
orComponentQuery.cast(model); | ||
val[k] = orComponentQuery._conditions; | ||
} | ||
} else if (path === '$where') { | ||
type = typeof val; | ||
if ('string' !== type && 'function' !== type) { | ||
throw new Error("Must have a string or function for $where"); | ||
} | ||
if ('function' === type) obj[path] = val.toString(); | ||
if ('function' === type) { | ||
obj[path] = val.toString(); | ||
} | ||
continue; | ||
} else { | ||
schematype = schema.path(path); | ||
if (!schematype) { | ||
@@ -139,4 +152,7 @@ // Handle potential embedded array queries | ||
, j = split.length | ||
, pathFirstHalf, pathLastHalf | ||
, remainingConds, castingQuery; | ||
, pathFirstHalf | ||
, pathLastHalf | ||
, remainingConds | ||
, castingQuery; | ||
// Find the part of the var path that is a path of the Schema | ||
@@ -148,2 +164,3 @@ while (j--) { | ||
} | ||
// If a substring of the input path resolves to an actual real path... | ||
@@ -156,11 +173,14 @@ if (schematype) { | ||
castingQuery = new Query(remainingConds); | ||
castingQuery.cast(schematype.caster); | ||
castingQuery.cast(model, schematype.caster); | ||
obj[path] = castingQuery._conditions[pathLastHalf]; | ||
} | ||
} else if (val === null || val === undefined) { | ||
continue; | ||
} else if (val.constructor == Object) { | ||
any$conditionals = Object.keys(val).some( function (k) { | ||
any$conditionals = Object.keys(val).some(function (k) { | ||
return k.charAt(0) === '$'; | ||
}); | ||
if (!any$conditionals) { | ||
@@ -178,9 +198,10 @@ obj[path] = schematype.castForQuery(val); | ||
if ($cond === '$ne' && nested === null) { | ||
if ('$ne' === $cond && null === nested) { | ||
continue; | ||
} else if ($cond === '$exists') { | ||
if ('boolean' !== typeof nested) | ||
} else if ('$exists' === $cond) { | ||
if ('boolean' !== typeof nested) { | ||
throw new Error("$exists parameter must be Boolean"); | ||
} | ||
continue; | ||
} else if ($cond === '$not') { | ||
} else if ('$not' === $cond) { | ||
this.cast(model, val[$cond]); | ||
@@ -341,7 +362,7 @@ } else { | ||
// TODO "immortal" cursors | ||
// TODO "immortal" cursors - (only work on capped collections) | ||
// TODO geoNear command | ||
// To be used idiomatically where Query#box and Query#center | ||
['wherein', '$wherein'].forEach( function (getter) { | ||
['wherein', '$wherein'].forEach(function (getter) { | ||
Object.defineProperty(Query.prototype, getter, { | ||
@@ -387,2 +408,3 @@ get: function () { | ||
*/ | ||
Query.prototype.select = | ||
@@ -415,2 +437,3 @@ Query.prototype.fields = function () { | ||
*/ | ||
Query.prototype.only = function (fields) { | ||
@@ -435,2 +458,3 @@ fields = this._parseOnlyExcludeFields.apply(this, arguments); | ||
*/ | ||
Query.prototype.exclude = function (fields) { | ||
@@ -468,2 +492,3 @@ fields = this._parseOnlyExcludeFields.apply(this, arguments); | ||
*/ | ||
Query.prototype._parseOnlyExcludeFields = function (fields) { | ||
@@ -473,2 +498,3 @@ if (1 === arguments.length && 'string' === typeof fields) { | ||
} else if (Array.isArray(fields)) { | ||
// do nothing | ||
} else { | ||
@@ -505,15 +531,16 @@ fields = [].slice.call(arguments); | ||
*/ | ||
Query.prototype._applyFields = function (fields) { | ||
var $fields | ||
, pathList; | ||
if (Array.isArray(fields)) { | ||
$fields = | ||
fields.reduce( function ($fields, field) { | ||
$fields[field] = 1; | ||
return $fields; | ||
}, {}); | ||
$fields = fields.reduce(function ($fields, field) { | ||
$fields[field] = 1; | ||
return $fields; | ||
}, {}); | ||
} else if (pathList = fields.only || fields.exclude) { | ||
$fields = | ||
$fields = | ||
this._parseOnlyExcludeFields(pathList) | ||
.reduce( function ($fields, field) { | ||
.reduce(function ($fields, field) { | ||
$fields[field] = fields.only ? 1: 0; | ||
@@ -617,2 +644,3 @@ return $fields; | ||
} | ||
var castQuery = this._conditions; | ||
@@ -623,3 +651,3 @@ | ||
cursor.toArray( function (err, docs) { | ||
cursor.toArray(function (err, docs) { | ||
if (err) return callback(err); | ||
@@ -640,4 +668,4 @@ | ||
}); | ||
}); | ||
}); | ||
return this; | ||
@@ -754,4 +782,5 @@ }; | ||
var options = this._optionsForExec(model); | ||
options.fields = this._fields; | ||
this.cast(model); | ||
@@ -762,3 +791,2 @@ var castQuery = this._conditions; | ||
if (err) return callback(err); | ||
if (!doc) return callback(null, null); | ||
@@ -772,2 +800,3 @@ | ||
}); | ||
return this; | ||
@@ -804,5 +833,5 @@ }; | ||
Query.prototype.update = function (doc, callback) { | ||
this.op = 'update'; | ||
this._updateArg = doc; | ||
var model = this.model | ||
@@ -822,2 +851,3 @@ , options = this._optionsForExec(model) | ||
} | ||
model.collection.update(castQuery, castDoc, options, callback); | ||
@@ -828,3 +858,3 @@ return this; | ||
/** | ||
* Casts the query, sends the remove command to | ||
* Casts the query, sends the remove command to | ||
* mongodb where the query contents, and then | ||
@@ -834,3 +864,3 @@ * invokes a callback upon receiving the command | ||
* | ||
* @param {Function} callback fn(err) | ||
* @param {Function} callback | ||
* @api public | ||
@@ -837,0 +867,0 @@ */ |
{ | ||
"name": "mongoose" | ||
, "description": "Mongoose MongoDB ORM" | ||
, "version": "1.3.2" | ||
, "version": "1.3.3" | ||
, "author": "Guillermo Rauch <guillermo@learnboost.com>" | ||
@@ -6,0 +6,0 @@ , "keywords": ["mongodb", "mongoose", "orm", "data", "datastore", "nosql"] |
@@ -1166,3 +1166,13 @@ | ||
} | ||
}, | ||
'nested mixed queries (x.y.z)': function () { | ||
var db = start() | ||
, BlogPostB = db.model('BlogPostB', collection); | ||
BlogPostB.find({ 'mixed.nested.stuff': 'skynet' }, function (err, docs) { | ||
db.close(); | ||
should.strictEqual(err, null); | ||
}); | ||
} | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3156002
213
27035