Skip to content

Commit

Permalink
Fixed a bug with aggregation helper not properly accepting readPrefer…
Browse files Browse the repository at this point in the history
…ence
  • Loading branch information
christkv committed Nov 27, 2012
1 parent 8b91e5c commit c08f44f
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
5 changes: 3 additions & 2 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1.1.12
-----------------
1.2 2012-11-27
--------------
- Honor connectTimeoutMS option for replicasets (Issue #750, https://github.com/aheckmann)
- Fix ping strategy regression (Issue #738, https://github.com/aheckmann)
- Small cleanup of code (Issue #753, https://github.com/sokra/node-mongodb-native)
Expand All @@ -13,6 +13,7 @@
- new MongoClient introduced as the point of connecting to MongoDB's instead of the Db
- open/close/db/connect methods implemented
- Implemented common URL connection format using MongoClient.connect allowing for simialar interface across all drivers.
- Fixed a bug with aggregation helper not properly accepting readPreference

1.1.11 2012-10-10
-----------------
Expand Down
70 changes: 70 additions & 0 deletions test/aggregation_framework_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,76 @@ exports.shouldCorrectlyFailAndReturnError = function(test) {
});
}

/**
* @ignore
*/
exports.shouldCorrectlyPassReadPreference = function(test) {
// Some docs for insertion
var docs = [{
title : "this is my title", author : "bob", posted : new Date() ,
pageViews : 5, tags : [ "fun" , "good" , "fun" ], other : { foo : 5 },
comments : [
{ author :"joe", text : "this is cool" }, { author :"sam", text : "this is bad" }
]}];

client.admin().serverInfo(function(err, result){
if(parseInt((result.version.replace(/\./g, ''))) >= 210) {
// Create a collection
client.createCollection('shouldCorrectlyFailAndReturnError', function(err, collection) {
// Override the command object for the db
var _command = client.command;
client.command = function(selector, options, callback) {
var args = Array.prototype.slice.call(arguments, 0);
test.equal("secondary", options.readPreference);
_command.apply(client, args);
}

// Insert the docs
collection.insert(docs, {w: 1}, function(err, result) {
// Execute aggregate
collection.aggregate(
{ $project : {
author : 1,
tags : 1,
}},
{ $32unwind : "$tags" },
{ $group : {
_id : { tags : 1 },
authors : { $addToSet : "$author" }
}},
{readPreference:'secondary'}
, function(err, result) {
// client.command = _command;

// Execute aggregate
collection.aggregate(
[{ $project : {
author : 1,
tags : 1,
}},
{ $32unwind : "$tags" },
{ $group : {
_id : { tags : 1 },
authors : { $addToSet : "$author" }
}}],
{readPreference:'secondary'}
, function(err, result) {
client.command = _command;
test.ok(err != null);
test.done();
});

test.ok(err != null);
test.done();
});
});
});
} else {
test.done();
}
});
}

// /**
// * @ignore
// */
Expand Down

0 comments on commit c08f44f

Please sign in to comment.