Skip to content
Browse files

fixed; sending safe/read options in Query#exec

closes #1895
  • Loading branch information...
1 parent e7df792 commit aa12fae17cc0a37cd49ba555bf9d229c92195788 Aaron Heckmann committed
Showing with 31 additions and 1 deletion.
  1. +2 −1 lib/query.js
  2. +29 −0 test/query.test.js
View
3 lib/query.js
@@ -904,6 +904,7 @@ Query.prototype._optionsForExec = function (model) {
var options = Query.base._optionsForExec.call(this);
delete options.populate;
+ model = model || this.model;
if (!model) {
return options;
@@ -912,7 +913,7 @@ Query.prototype._optionsForExec = function (model) {
options.safe = model.schema.options.safe;
}
- if(!('readPreference' in options) && model.schema.options.read) {
+ if (!('readPreference' in options) && model.schema.options.read) {
options.readPreference = model.schema.options.read;
}
View
29 test/query.test.js
@@ -1387,6 +1387,35 @@ describe('Query', function(){
done();
})
+ it('and sends it though the driver', function(done) {
+ var db = start();
+ var options = { read: 'secondary', safe: { w: 'majority' }};
+ var schema = Schema({ name: String }, options);
+ var M = db.model(random(), schema);
+ var q = M.find();
+
+ // stub the internal query options call
+ var getopts = q._optionsForExec;
+ q._optionsForExec = function(model) {
+ q._optionsForExec = getopts;
+
+ var ret = getopts.call(this, model);
+
+ assert.ok(ret.readPreference);
+ assert.equal('secondary', ret.readPreference.mode);
+ assert.deepEqual({ w: 'majority' }, ret.safe);
+ called = true;
+
+ return ret;
+ }
+
+ q.exec(function(err, res) {
+ if (err) return done(err);
+ assert.ok(called);
+ done();
+ });
+ });
+
})
})
})

0 comments on commit aa12fae

Please sign in to comment.
Something went wrong with that request. Please try again.