Skip to content

Commit

Permalink
Added more collation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Jul 28, 2016
1 parent 31fc44d commit 87a6c3e
Show file tree
Hide file tree
Showing 4 changed files with 491 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/bulk/ordered.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ OrderedBulkOperation.prototype.raw = function(op) {
var multi = op.updateOne || op.replaceOne ? false : true;
var operation = {q: op[key].filter, u: op[key].update || op[key].replacement, multi: multi}
operation.upsert = op[key].upsert ? true: false;
if(op.collation) operation.collation = op.collation;
return addToOperationsList(this, common.UPDATE, operation);
}

Expand All @@ -331,6 +332,7 @@ OrderedBulkOperation.prototype.raw = function(op) {
if(op.deleteOne || op.deleteMany) {
var limit = op.deleteOne ? 1 : 0;
var operation = {q: op[key].filter, limit: limit}
if(op.collation) operation.collation = op.collation;
return addToOperationsList(this, common.REMOVE, operation);
}

Expand Down
29 changes: 29 additions & 0 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,25 @@ var bulkWrite = function(self, operations, options, callback) {
// Create the bulk operation
var bulk = options.ordered == true || options.ordered == null ? self.initializeOrderedBulkOp(options) : self.initializeUnorderedBulkOp(options);

// Do we have a collation
var collation = false;

// for each op go through and add to the bulk
try {
for(var i = 0; i < operations.length; i++) {
// Get the operation type
var key = Object.keys(operations[i])[0];
// Check if we have a collation
if(operations[i][key].collation) {
collation = true;
}

// // Have we specified collation, apply it
// decorateWithCollation(operations[i], self, options);
// console.log("================ bulkWrite")
// console.dir(operations[i])

// Pass to the raw bulk
bulk.raw(operations[i]);
}
} catch(err) {
Expand All @@ -617,6 +633,12 @@ var bulkWrite = function(self, operations, options, callback) {
// Final options for write concern
var finalOptions = writeConcern(shallowClone(options), self.s.db, self, options);
var writeCon = finalOptions.writeConcern ? finalOptions.writeConcern : {};
var capabilities = self.s.topology.capabilities();

// Did the user pass in a collation, check if our write server supports it
if(collation && capabilities && !capabilities.commandsTakeCollation) {
return callback(new MongoError(f('server/primary/mongos does not support collation')));
}

// Execute the bulk
bulk.execute(writeCon, function(err, r) {
Expand Down Expand Up @@ -1598,11 +1620,18 @@ Collection.prototype.createIndexes = function(indexSpecs, callback) {
}

var createIndexes = function(self, indexSpecs, callback) {
var capabilities = self.s.topology.capabilities();

// Ensure we generate the correct name if the parameter is not set
for(var i = 0; i < indexSpecs.length; i++) {
if(indexSpecs[i].name == null) {
var keys = [];

// Did the user pass in a collation, check if our write server supports it
if(indexSpecs[i].collation && capabilities && !capabilities.commandsTakeCollation) {
return callback(new MongoError(f('server/primary/mongos does not support collation')));
}

for(var name in indexSpecs[i].key) {
keys.push(f('%s_%s', name, indexSpecs[i].key[name]));
}
Expand Down
12 changes: 12 additions & 0 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,18 @@ var createIndexUsingCreateIndexes = function(self, name, fieldOrSpec, options, c
}
}

// Get capabilities
var capabilities = self.s.topology.capabilities();

// Did the user pass in a collation, check if our write server supports it
if(indexes[0].collation && capabilities && !capabilities.commandsTakeCollation) {
// Create a new error
var error = new MongoError(f('server/primary/mongos does not support collation'));
error.code = 67;
// Return the error
return callback(error);
}

// Create command, apply write concern to command
var cmd = writeConcern({createIndexes: name, indexes: indexes}, self, options);

Expand Down
Loading

0 comments on commit 87a6c3e

Please sign in to comment.