@@ -605,9 +605,25 @@ var bulkWrite = function(self, operations, options, callback) {
605
605
// Create the bulk operation
606
606
var bulk = options . ordered == true || options . ordered == null ? self . initializeOrderedBulkOp ( options ) : self . initializeUnorderedBulkOp ( options ) ;
607
607
608
+ // Do we have a collation
609
+ var collation = false ;
610
+
608
611
// for each op go through and add to the bulk
609
612
try {
610
613
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
611
627
bulk . raw ( operations [ i ] ) ;
612
628
}
613
629
} catch ( err ) {
@@ -617,6 +633,12 @@ var bulkWrite = function(self, operations, options, callback) {
617
633
// Final options for write concern
618
634
var finalOptions = writeConcern ( shallowClone ( options ) , self . s . db , self , options ) ;
619
635
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
+ }
620
642
621
643
// Execute the bulk
622
644
bulk . execute ( writeCon , function ( err , r ) {
@@ -1598,11 +1620,18 @@ Collection.prototype.createIndexes = function(indexSpecs, callback) {
1598
1620
}
1599
1621
1600
1622
var createIndexes = function ( self , indexSpecs , callback ) {
1623
+ var capabilities = self . s . topology . capabilities ( ) ;
1624
+
1601
1625
// Ensure we generate the correct name if the parameter is not set
1602
1626
for ( var i = 0 ; i < indexSpecs . length ; i ++ ) {
1603
1627
if ( indexSpecs [ i ] . name == null ) {
1604
1628
var keys = [ ] ;
1605
1629
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
+
1606
1635
for ( var name in indexSpecs [ i ] . key ) {
1607
1636
keys . push ( f ( '%s_%s' , name , indexSpecs [ i ] . key [ name ] ) ) ;
1608
1637
}
0 commit comments