Skip to content

Commit

Permalink
Merge pull request #5080 from zoellner/master
Browse files Browse the repository at this point in the history
fix(query): handle $type for arrays
  • Loading branch information
vkarpov15 authored Mar 19, 2017
2 parents 249653b + 80b325c commit 74cdbdd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/schema/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var $exists = require('./operators/exists');
var $type = require('./operators/type');
var SchemaType = require('../schematype');
var CastError = SchemaType.CastError;
var Types = {
Expand Down Expand Up @@ -319,6 +320,7 @@ handle.$minDistance =
handle.$maxDistance = castToNumber;

handle.$exists = $exists;
handle.$type = $type;

handle.$eq =
handle.$gt =
Expand Down
13 changes: 13 additions & 0 deletions lib/schema/operators/type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

/*!
* ignore
*/

module.exports = function(val) {
if (typeof val !== 'number' && typeof val !== 'string') {
throw new Error('$type parameter must be number or string');
}

return val;
};
9 changes: 2 additions & 7 deletions lib/schematype.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

var $exists = require('./schema/operators/exists');
var $type = require('./schema/operators/type');
var utils = require('./utils');
var MongooseError = require('./error');
var CastError = MongooseError.CastError;
Expand Down Expand Up @@ -922,13 +923,7 @@ SchemaType.prototype.$conditionalHandlers = {
$ne: handleSingle,
$nin: handleArray,
$exists: $exists,
$type: function(val) {
if (typeof val !== 'number' && typeof val !== 'string') {
throw new Error('$type parameter must be number or string');
}

return val;
}
$type: $type
};

/**
Expand Down

0 comments on commit 74cdbdd

Please sign in to comment.