@@ -122,6 +122,8 @@ var Collection = function(db, topology, dbName, name, pkFactory, options) {
122
122
, promiseLibrary : promiseLibrary
123
123
// Read Concern
124
124
, readConcern : options . readConcern
125
+ // Collation
126
+ , collation : options . collation
125
127
}
126
128
}
127
129
@@ -351,6 +353,9 @@ Collection.prototype.find = function() {
351
353
findCommand . readConcern = this . s . readConcern ;
352
354
}
353
355
356
+ // Decorate find command with collation options
357
+ decorateWithCollation ( findCommand , this , options ) ;
358
+
354
359
// Create the cursor
355
360
if ( typeof callback == 'function' ) return handleCallback ( callback , null , this . s . topology . cursor ( this . s . namespace , findCommand , newOptions ) ) ;
356
361
return this . s . topology . cursor ( this . s . namespace , findCommand , newOptions ) ;
@@ -623,11 +628,6 @@ var bulkWrite = function(self, operations, options, callback) {
623
628
return callback ( toError ( r . getWriteErrorAt ( 0 ) ) , r ) ;
624
629
}
625
630
626
- // console.log("!!!!!! BULK EXECUTE FINISHED")
627
- // console.dir(err)
628
- // console.dir(r)
629
-
630
- // if(err) return callback(err);
631
631
r . insertedCount = r . nInserted ;
632
632
r . matchedCount = r . nMatched ;
633
633
r . modifiedCount = r . nModified || 0 ;
@@ -1006,6 +1006,9 @@ var updateDocuments = function(self, selector, document, options, callback) {
1006
1006
op . upsert = typeof options . upsert == 'boolean' ? options . upsert : false ;
1007
1007
op . multi = typeof options . multi == 'boolean' ? options . multi : false ;
1008
1008
1009
+ // Have we specified collation
1010
+ decorateWithCollation ( finalOptions , self , options ) ;
1011
+
1009
1012
// Update options
1010
1013
self . s . topology . update ( self . s . namespace , [ op ] , finalOptions , function ( err , result ) {
1011
1014
if ( callback == null ) return ;
@@ -1161,6 +1164,7 @@ Collection.prototype.deleteMany = function(filter, options, callback) {
1161
1164
1162
1165
var deleteMany = function ( self , filter , options , callback ) {
1163
1166
options . single = false ;
1167
+
1164
1168
removeDocuments ( self , filter , options , function ( err , r ) {
1165
1169
if ( callback == null ) return ;
1166
1170
if ( err && callback ) return callback ( err ) ;
@@ -1192,6 +1196,9 @@ var removeDocuments = function(self, selector, options, callback) {
1192
1196
var op = { q : selector , limit : 0 } ;
1193
1197
if ( options . single ) op . limit = 1 ;
1194
1198
1199
+ // Have we specified collation
1200
+ decorateWithCollation ( finalOptions , self , options ) ;
1201
+
1195
1202
// Execute the remove
1196
1203
self . s . topology . remove ( self . s . namespace , [ op ] , finalOptions , function ( err , result ) {
1197
1204
if ( callback == null ) return ;
@@ -1989,6 +1996,9 @@ var count = function(self, query, options, callback) {
1989
1996
cmd . readConcern = self . s . readConcern ;
1990
1997
}
1991
1998
1999
+ // Have we specified collation
2000
+ decorateWithCollation ( cmd , self , options ) ;
2001
+
1992
2002
// Execute command
1993
2003
self . s . db . command ( cmd , options , function ( err , result ) {
1994
2004
if ( err ) return handleCallback ( callback , err ) ;
@@ -2050,6 +2060,9 @@ var distinct = function(self, key, query, options, callback) {
2050
2060
cmd . readConcern = self . s . readConcern ;
2051
2061
}
2052
2062
2063
+ // Have we specified collation
2064
+ decorateWithCollation ( cmd , self , options ) ;
2065
+
2053
2066
// Execute the command
2054
2067
self . s . db . command ( cmd , options , function ( err , result ) {
2055
2068
if ( err ) return handleCallback ( callback , err ) ;
@@ -2408,6 +2421,9 @@ var findAndModify = function(self, query, sort, doc, options, callback) {
2408
2421
queryObject . bypassDocumentValidation = finalOptions . bypassDocumentValidation ;
2409
2422
}
2410
2423
2424
+ // Have we specified collation
2425
+ decorateWithCollation ( queryObject , self , options ) ;
2426
+
2411
2427
// Execute the command
2412
2428
self . s . db . command ( queryObject
2413
2429
, options , function ( err , result ) {
@@ -2472,6 +2488,19 @@ function decorateWithWriteConcern(command, self, options) {
2472
2488
}
2473
2489
}
2474
2490
2491
+ function decorateWithCollation ( command , self , options ) {
2492
+ // Do we support collation 3.4 and higher
2493
+ if ( self . s . topology . capabilities ( ) . commandsTakeCollation ) {
2494
+ if ( options . collation && typeof options . collation == 'object' ) {
2495
+ command . collation = options . collation ;
2496
+ } else if ( self . s . collation && typeof self . s . collation == 'object' ) {
2497
+ command . collation = self . s . collation ;
2498
+ } else if ( self . s . db . s . collation && typeof self . s . db . s . collation == 'object' ) {
2499
+ command . collation = self . s . db . s . collation ;
2500
+ }
2501
+ }
2502
+ }
2503
+
2475
2504
/**
2476
2505
* Execute an aggregation framework pipeline against the collection, needs MongoDB >= 2.2
2477
2506
* @method
@@ -2533,6 +2562,8 @@ Collection.prototype.aggregate = function(pipeline, options, callback) {
2533
2562
2534
2563
// Decorate command with writeConcern if supported
2535
2564
decorateWithWriteConcern ( command , self , options ) ;
2565
+ // Have we specified collation
2566
+ decorateWithCollation ( command , self , options ) ;
2536
2567
2537
2568
// If we have bypassDocumentValidation set
2538
2569
if ( typeof options . bypassDocumentValidation == 'boolean' ) {
@@ -2767,6 +2798,9 @@ var geoNear = function(self, x, y, point, options, callback) {
2767
2798
commandObject . readConcern = self . s . readConcern ;
2768
2799
}
2769
2800
2801
+ // Have we specified collation
2802
+ decorateWithCollation ( commandObject , self , options ) ;
2803
+
2770
2804
// Execute the command
2771
2805
self . s . db . command ( commandObject , options , function ( err , res ) {
2772
2806
if ( err ) return handleCallback ( callback , err ) ;
@@ -2976,6 +3010,9 @@ var group = function(self, keys, condition, initial, reduce, finalize, command,
2976
3010
selector . readConcern = self . s . readConcern ;
2977
3011
}
2978
3012
3013
+ // Have we specified collation
3014
+ decorateWithCollation ( selector , self , options ) ;
3015
+
2979
3016
// Execute command
2980
3017
self . s . db . command ( selector , options , function ( err , result ) {
2981
3018
if ( err ) return handleCallback ( callback , err , null ) ;
@@ -3122,6 +3159,9 @@ var mapReduce = function(self, map, reduce, options, callback) {
3122
3159
mapCommandHash . bypassDocumentValidation = options . bypassDocumentValidation ;
3123
3160
}
3124
3161
3162
+ // Have we specified collation
3163
+ decorateWithCollation ( mapCommandHash , self , options ) ;
3164
+
3125
3165
// Execute command
3126
3166
self . s . db . command ( mapCommandHash , { readPreference :options . readPreference } , function ( err , result ) {
3127
3167
if ( err ) return handleCallback ( callback , err ) ;
@@ -3254,6 +3294,7 @@ var testForFields = {
3254
3294
limit : 1 , sort : 1 , fields :1 , skip : 1 , hint : 1 , explain : 1 , snapshot : 1 , timeout : 1 , tailable : 1 , tailableRetryInterval : 1
3255
3295
, numberOfRetries : 1 , awaitdata : 1 , awaitData : 1 , exhaust : 1 , batchSize : 1 , returnKey : 1 , maxScan : 1 , min : 1 , max : 1 , showDiskLoc : 1
3256
3296
, comment : 1 , raw : 1 , readPreference : 1 , partial : 1 , read : 1 , dbName : 1 , oplogReplay : 1 , connection : 1 , maxTimeMS : 1 , transforms : 1
3297
+ , collation : 1
3257
3298
}
3258
3299
3259
3300
module . exports = Collection ;
0 commit comments