@@ -889,6 +889,7 @@ define.classMethod('insert', { callback: true, promise: true });
889
889
*/
890
890
Collection . prototype . updateOne = function ( filter , update , options , callback ) {
891
891
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
892
+ options = options || { } ;
892
893
893
894
var err = checkForAtomicOperators ( update ) ;
894
895
if ( err ) {
@@ -1013,6 +1014,7 @@ define.classMethod('replaceOne', { callback: true, promise: true });
1013
1014
*/
1014
1015
Collection . prototype . updateMany = function ( filter , update , options , callback ) {
1015
1016
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1017
+ options = options || { } ;
1016
1018
1017
1019
var err = checkForAtomicOperators ( update ) ;
1018
1020
if ( err ) {
@@ -1119,13 +1121,22 @@ var updateDocuments = function(self, selector, document, options, callback) {
1119
1121
* @deprecated use updateOne, updateMany or bulkWrite
1120
1122
*/
1121
1123
Collection . prototype . update = function ( selector , document , options , callback ) {
1124
+ if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1125
+ options = options || { } ;
1126
+
1122
1127
// Add ignoreUndfined
1123
1128
if ( this . s . options . ignoreUndefined ) {
1124
1129
options = shallowClone ( options ) ;
1125
1130
options . ignoreUndefined = this . s . options . ignoreUndefined ;
1126
1131
}
1127
1132
1128
- return executeOperation ( this . s . topology , updateDocuments , [ this , selector , document , options , callback ] ) ;
1133
+ return executeOperation ( this . s . topology , updateDocuments , [
1134
+ this ,
1135
+ selector ,
1136
+ document ,
1137
+ options ,
1138
+ callback
1139
+ ] ) ;
1129
1140
} ;
1130
1141
1131
1142
define . classMethod ( 'update' , { callback : true , promise : true } ) ;
@@ -1498,13 +1509,13 @@ define.classMethod('drop', { callback: true, promise: true });
1498
1509
*/
1499
1510
Collection . prototype . options = function ( opts , callback ) {
1500
1511
if ( typeof opts === 'function' ) ( callback = opts ) , ( opts = { } ) ;
1512
+ opts = opts || { } ;
1501
1513
1502
1514
return executeOperation ( this . s . topology , options , [ this , opts , callback ] ) ;
1503
1515
} ;
1504
1516
1505
1517
var options = function ( self , opts , callback ) {
1506
- opts = assign ( { } , { name : self . s . name } , opts ) ;
1507
- self . s . db . listCollections ( opts ) . toArray ( function ( err , collections ) {
1518
+ self . s . db . listCollections ( { name : self . s . name } , opts ) . toArray ( function ( err , collections ) {
1508
1519
if ( err ) return handleCallback ( callback , err ) ;
1509
1520
if ( collections . length === 0 ) {
1510
1521
return handleCallback (
@@ -1530,6 +1541,7 @@ define.classMethod('options', { callback: true, promise: true });
1530
1541
*/
1531
1542
Collection . prototype . isCapped = function ( options , callback ) {
1532
1543
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1544
+ options = options || { } ;
1533
1545
1534
1546
return executeOperation ( this . s . topology , isCapped , [ this , options , callback ] ) ;
1535
1547
} ;
@@ -1596,6 +1608,7 @@ define.classMethod('createIndex', { callback: true, promise: true });
1596
1608
*/
1597
1609
Collection . prototype . createIndexes = function ( indexSpecs , options , callback ) {
1598
1610
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1611
+ options = options || { } ;
1599
1612
1600
1613
return executeOperation ( this . s . topology , createIndexes , [ this , indexSpecs , options , callback ] ) ;
1601
1614
} ;
@@ -1842,6 +1855,7 @@ define.classMethod('ensureIndex', { callback: true, promise: true });
1842
1855
*/
1843
1856
Collection . prototype . indexExists = function ( indexes , options , callback ) {
1844
1857
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1858
+ options = options || { } ;
1845
1859
1846
1860
return executeOperation ( this . s . topology , indexExists , [ this , indexes , options , callback ] ) ;
1847
1861
} ;
@@ -1939,8 +1953,9 @@ var count = function(self, query, options, callback) {
1939
1953
if ( hint ) cmd . hint = hint ;
1940
1954
1941
1955
options = shallowClone ( options ) ;
1956
+
1942
1957
// Ensure we have the right read preference inheritance
1943
- options = getReadPreference ( self , options , self . s . db , self ) ;
1958
+ options = getReadPreference ( self , options , self . s . db ) ;
1944
1959
1945
1960
// Do we have a readConcern specified
1946
1961
if ( self . s . readConcern ) {
@@ -1977,7 +1992,13 @@ Collection.prototype.distinct = function(key, query, options, callback) {
1977
1992
var queryOption = args . length ? args . shift ( ) || { } : { } ;
1978
1993
var optionsOption = args . length ? args . shift ( ) || { } : { } ;
1979
1994
1980
- return executeOperation ( this . s . topology , distinct , [ this , key , queryOption , optionsOption , callback ] ) ;
1995
+ return executeOperation ( this . s . topology , distinct , [
1996
+ this ,
1997
+ key ,
1998
+ queryOption ,
1999
+ optionsOption ,
2000
+ callback
2001
+ ] ) ;
1981
2002
} ;
1982
2003
1983
2004
var distinct = function ( self , key , query , options , callback ) {
@@ -2025,6 +2046,7 @@ define.classMethod('distinct', { callback: true, promise: true });
2025
2046
*/
2026
2047
Collection . prototype . indexes = function ( options , callback ) {
2027
2048
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
2049
+ options = options || { } ;
2028
2050
2029
2051
return executeOperation ( this . s . topology , indexes , [ this , options , callback ] ) ;
2030
2052
} ;
@@ -2148,7 +2170,13 @@ Collection.prototype.findOneAndReplace = function(filter, replacement, options,
2148
2170
if ( replacement == null || typeof replacement !== 'object' )
2149
2171
throw toError ( 'replacement parameter must be an object' ) ;
2150
2172
2151
- return executeOperation ( this . s . topology , findOneAndReplace , [ this , filter , replacement , options , callback ] ) ;
2173
+ return executeOperation ( this . s . topology , findOneAndReplace , [
2174
+ this ,
2175
+ filter ,
2176
+ replacement ,
2177
+ options ,
2178
+ callback
2179
+ ] ) ;
2152
2180
} ;
2153
2181
2154
2182
var findOneAndReplace = function ( self , filter , replacement , options , callback ) {
@@ -2192,7 +2220,13 @@ Collection.prototype.findOneAndUpdate = function(filter, update, options, callba
2192
2220
if ( update == null || typeof update !== 'object' )
2193
2221
throw toError ( 'update parameter must be an object' ) ;
2194
2222
2195
- return executeOperation ( this . s . topology , findOneAndUpdate , [ this , filter , update , options , callback ] ) ;
2223
+ return executeOperation ( this . s . topology , findOneAndUpdate , [
2224
+ this ,
2225
+ filter ,
2226
+ update ,
2227
+ options ,
2228
+ callback
2229
+ ] ) ;
2196
2230
} ;
2197
2231
2198
2232
var findOneAndUpdate = function ( self , filter , update , options , callback ) {
@@ -2241,7 +2275,14 @@ Collection.prototype.findAndModify = function(query, sort, doc, options, callbac
2241
2275
// Force read preference primary
2242
2276
options . readPreference = ReadPreference . PRIMARY ;
2243
2277
2244
- return executeOperation ( this . s . topology , findAndModify , [ this , query , sort , doc , options , callback ] ) ;
2278
+ return executeOperation ( this . s . topology , findAndModify , [
2279
+ this ,
2280
+ query ,
2281
+ sort ,
2282
+ doc ,
2283
+ options ,
2284
+ callback
2285
+ ] ) ;
2245
2286
} ;
2246
2287
2247
2288
var findAndModify = function ( self , query , sort , doc , options , callback ) {
@@ -2679,7 +2720,8 @@ var geoNear = function(self, x, y, point, options, callback) {
2679
2720
var exclude = {
2680
2721
readPreference : true ,
2681
2722
geoNear : true ,
2682
- near : true
2723
+ near : true ,
2724
+ session : true
2683
2725
} ;
2684
2726
2685
2727
// Filter out any excluded objects
@@ -2736,7 +2778,7 @@ var geoHaystackSearch = function(self, x, y, options, callback) {
2736
2778
} ;
2737
2779
2738
2780
// Remove read preference from hash if it exists
2739
- commandObject = decorateCommand ( commandObject , options , { readPreference : true } ) ;
2781
+ commandObject = decorateCommand ( commandObject , options , { readPreference : true , session : true } ) ;
2740
2782
2741
2783
options = shallowClone ( options ) ;
2742
2784
// Ensure we have the right read preference inheritance
@@ -3014,7 +3056,7 @@ var mapReduce = function(self, map, reduce, options, callback) {
3014
3056
} ;
3015
3057
3016
3058
// Exclusion list
3017
- var exclusionList = [ 'readPreference' ] ;
3059
+ var exclusionList = [ 'readPreference' , 'session' ] ;
3018
3060
3019
3061
// Add any other options passed in
3020
3062
for ( var n in options ) {
0 commit comments