Skip to content

Commit 87a6c3e

Browse files
committed
Added more collation tests
1 parent 31fc44d commit 87a6c3e

File tree

4 files changed

+491
-0
lines changed

4 files changed

+491
-0
lines changed

lib/bulk/ordered.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ OrderedBulkOperation.prototype.raw = function(op) {
318318
var multi = op.updateOne || op.replaceOne ? false : true;
319319
var operation = {q: op[key].filter, u: op[key].update || op[key].replacement, multi: multi}
320320
operation.upsert = op[key].upsert ? true: false;
321+
if(op.collation) operation.collation = op.collation;
321322
return addToOperationsList(this, common.UPDATE, operation);
322323
}
323324

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

lib/collection.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,25 @@ var bulkWrite = function(self, operations, options, callback) {
605605
// Create the bulk operation
606606
var bulk = options.ordered == true || options.ordered == null ? self.initializeOrderedBulkOp(options) : self.initializeUnorderedBulkOp(options);
607607

608+
// Do we have a collation
609+
var collation = false;
610+
608611
// for each op go through and add to the bulk
609612
try {
610613
for(var i = 0; i < operations.length; i++) {
614+
// Get the operation type
615+
var key = Object.keys(operations[i])[0];
616+
// Check if we have a collation
617+
if(operations[i][key].collation) {
618+
collation = true;
619+
}
620+
621+
// // Have we specified collation, apply it
622+
// decorateWithCollation(operations[i], self, options);
623+
// console.log("================ bulkWrite")
624+
// console.dir(operations[i])
625+
626+
// Pass to the raw bulk
611627
bulk.raw(operations[i]);
612628
}
613629
} catch(err) {
@@ -617,6 +633,12 @@ var bulkWrite = function(self, operations, options, callback) {
617633
// Final options for write concern
618634
var finalOptions = writeConcern(shallowClone(options), self.s.db, self, options);
619635
var writeCon = finalOptions.writeConcern ? finalOptions.writeConcern : {};
636+
var capabilities = self.s.topology.capabilities();
637+
638+
// Did the user pass in a collation, check if our write server supports it
639+
if(collation && capabilities && !capabilities.commandsTakeCollation) {
640+
return callback(new MongoError(f('server/primary/mongos does not support collation')));
641+
}
620642

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

16001622
var createIndexes = function(self, indexSpecs, callback) {
1623+
var capabilities = self.s.topology.capabilities();
1624+
16011625
// Ensure we generate the correct name if the parameter is not set
16021626
for(var i = 0; i < indexSpecs.length; i++) {
16031627
if(indexSpecs[i].name == null) {
16041628
var keys = [];
16051629

1630+
// Did the user pass in a collation, check if our write server supports it
1631+
if(indexSpecs[i].collation && capabilities && !capabilities.commandsTakeCollation) {
1632+
return callback(new MongoError(f('server/primary/mongos does not support collation')));
1633+
}
1634+
16061635
for(var name in indexSpecs[i].key) {
16071636
keys.push(f('%s_%s', name, indexSpecs[i].key[name]));
16081637
}

lib/db.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,18 @@ var createIndexUsingCreateIndexes = function(self, name, fieldOrSpec, options, c
17291729
}
17301730
}
17311731

1732+
// Get capabilities
1733+
var capabilities = self.s.topology.capabilities();
1734+
1735+
// Did the user pass in a collation, check if our write server supports it
1736+
if(indexes[0].collation && capabilities && !capabilities.commandsTakeCollation) {
1737+
// Create a new error
1738+
var error = new MongoError(f('server/primary/mongos does not support collation'));
1739+
error.code = 67;
1740+
// Return the error
1741+
return callback(error);
1742+
}
1743+
17321744
// Create command, apply write concern to command
17331745
var cmd = writeConcern({createIndexes: name, indexes: indexes}, self, options);
17341746

0 commit comments

Comments
 (0)