Skip to content

Commit

Permalink
docs(query): correct function signature for .mod() helper
Browse files Browse the repository at this point in the history
Fix #1806
  • Loading branch information
vkarpov15 committed Nov 26, 2017
1 parent 16a41e5 commit 3a88543
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,17 +531,51 @@ Query.prototype.slice = function() {
*/

/**
* Specifies a `$mod` condition
* Specifies a `$mod` condition, filters documents for documents whose
* `path` property is a number that is equal to `remainder` modulo `divisor`.
*
* ####Example
*
* // All find products whose inventory is odd
* Product.find().mod('inventory', [2, 1]);
* Product.find().where('inventory').mod([2, 1]);
* // This syntax is a little strange, but supported.
* Product.find().where('inventory').mod(2, 1);
*
* @method mod
* @memberOf Query
* @param {String} [path]
* @param {Number} val
* @param {Array} val must be of length 2, first element is `divisor`, 2nd element is `remainder`.
* @return {Query} this
* @see $mod http://docs.mongodb.org/manual/reference/operator/mod/
* @api public
*/

Query.prototype.mod = function() {
var val;
var path;

if (arguments.length === 1) {
this._ensurePath('mod');
val = arguments[0];
path = this._path;
} else if (arguments.length === 2 && !Array.isArray(arguments[1])) {
this._ensurePath('mod');
val = slice(arguments);
path = this._path;
} else if (arguments.length === 3) {
val = slice(arguments, 1);
path = arguments[0];
} else {
val = arguments[1];
path = arguments[0];
}

var conds = this._conditions[path] || (this._conditions[path] = {});
conds.$mod = val;
return this;
};

/**
* Specifies an `$exists` condition
*
Expand Down

0 comments on commit 3a88543

Please sign in to comment.