Skip to content

Commit

Permalink
added; Query#slaveOk() support
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed Jul 6, 2011
1 parent 8a8b026 commit ee80882
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/mongoose/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ Query.prototype.where = function (path, val) {

Query.prototype.notEqualTo = Query.prototype.ne;

['mod', 'near'].forEach( function ($conditional) {
;['mod', 'near'].forEach( function ($conditional) {
Query.prototype['$' + $conditional] =
Query.prototype[$conditional] = function (path, val) {
if (arguments.length === 1) {
Expand Down Expand Up @@ -346,7 +346,7 @@ Query.prototype.elemMatch = function (path, criteria) {
return this;
};

['maxscan'].forEach( function (method) {
;['maxscan'].forEach( function (method) {
Query.prototype[method] = function (v) {
this.options[method] = v;
return this;
Expand All @@ -366,7 +366,7 @@ Query.prototype.explain = function () {
// 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, {
get: function () {
return this;
Expand Down Expand Up @@ -423,7 +423,7 @@ Query.prototype.fields = function () {
};

/**
* Chainable method for adding the specified fields to the
* Chainable method for adding the specified fields to the
* object of fields to only include.
*
* Examples:
Expand Down Expand Up @@ -589,7 +589,7 @@ Query.prototype.desc = function () {
return this;
};

['limit', 'skip', 'maxscan', 'snapshot'].forEach( function (method) {
;['limit', 'skip', 'maxscan', 'snapshot'].forEach( function (method) {
Query.prototype[method] = function (v) {
this.options[method] = v;
return this;
Expand Down Expand Up @@ -627,6 +627,21 @@ Query.prototype.hint = function (v, multi) {
return this;
};

/**
* Sets slaveOk option
*
* new Query().slaveOk() <== true
* new Query().slaveOk(true)
* new Query().slaveOk(false)
*
* @param {Boolean} v (defaults to true)
*/

Query.prototype.slaveOk = function (v) {
this.options.slaveOk = arguments.length ? !!v : true;
return this;
};

Query.prototype.execFind = function (callback) {
var model = this.model
, options = this._optionsForExec(model);
Expand Down
14 changes: 14 additions & 0 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,20 @@ module.exports = {
query.options.maxscan.should.equal(100);
},

'test Query#slaveOk': function () {
var query = new Query();
query.slaveOk();
query.options.slaveOk.should.be.true;

var query = new Query();
query.slaveOk(true);
query.options.slaveOk.should.be.true;

var query = new Query();
query.slaveOk(false);
query.options.slaveOk.should.be.false;
},

'test Query#hint': function () {
var query = new Query();
query.hint('indexAttributeA', 1, 'indexAttributeB', -1);
Expand Down

0 comments on commit ee80882

Please sign in to comment.