Skip to content

Commit 3a88543

Browse files
committed
docs(query): correct function signature for .mod() helper
Fix #1806
1 parent 16a41e5 commit 3a88543

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

lib/query.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,17 +531,51 @@ Query.prototype.slice = function() {
531531
*/
532532

533533
/**
534-
* Specifies a `$mod` condition
534+
* Specifies a `$mod` condition, filters documents for documents whose
535+
* `path` property is a number that is equal to `remainder` modulo `divisor`.
536+
*
537+
* ####Example
538+
*
539+
* // All find products whose inventory is odd
540+
* Product.find().mod('inventory', [2, 1]);
541+
* Product.find().where('inventory').mod([2, 1]);
542+
* // This syntax is a little strange, but supported.
543+
* Product.find().where('inventory').mod(2, 1);
535544
*
536545
* @method mod
537546
* @memberOf Query
538547
* @param {String} [path]
539-
* @param {Number} val
548+
* @param {Array} val must be of length 2, first element is `divisor`, 2nd element is `remainder`.
540549
* @return {Query} this
541550
* @see $mod http://docs.mongodb.org/manual/reference/operator/mod/
542551
* @api public
543552
*/
544553

554+
Query.prototype.mod = function() {
555+
var val;
556+
var path;
557+
558+
if (arguments.length === 1) {
559+
this._ensurePath('mod');
560+
val = arguments[0];
561+
path = this._path;
562+
} else if (arguments.length === 2 && !Array.isArray(arguments[1])) {
563+
this._ensurePath('mod');
564+
val = slice(arguments);
565+
path = this._path;
566+
} else if (arguments.length === 3) {
567+
val = slice(arguments, 1);
568+
path = arguments[0];
569+
} else {
570+
val = arguments[1];
571+
path = arguments[0];
572+
}
573+
574+
var conds = this._conditions[path] || (this._conditions[path] = {});
575+
conds.$mod = val;
576+
return this;
577+
};
578+
545579
/**
546580
* Specifies an `$exists` condition
547581
*

0 commit comments

Comments
 (0)