@@ -889,6 +889,7 @@ define.classMethod('insert', { callback: true, promise: true });
889889 */
890890Collection . prototype . updateOne = function ( filter , update , options , callback ) {
891891 if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
892+ options = options || { } ;
892893
893894 var err = checkForAtomicOperators ( update ) ;
894895 if ( err ) {
@@ -1013,6 +1014,7 @@ define.classMethod('replaceOne', { callback: true, promise: true });
10131014 */
10141015Collection . prototype . updateMany = function ( filter , update , options , callback ) {
10151016 if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1017+ options = options || { } ;
10161018
10171019 var err = checkForAtomicOperators ( update ) ;
10181020 if ( err ) {
@@ -1119,13 +1121,22 @@ var updateDocuments = function(self, selector, document, options, callback) {
11191121 * @deprecated use updateOne, updateMany or bulkWrite
11201122 */
11211123Collection . prototype . update = function ( selector , document , options , callback ) {
1124+ if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1125+ options = options || { } ;
1126+
11221127 // Add ignoreUndfined
11231128 if ( this . s . options . ignoreUndefined ) {
11241129 options = shallowClone ( options ) ;
11251130 options . ignoreUndefined = this . s . options . ignoreUndefined ;
11261131 }
11271132
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+ ] ) ;
11291140} ;
11301141
11311142define . classMethod ( 'update' , { callback : true , promise : true } ) ;
@@ -1498,13 +1509,13 @@ define.classMethod('drop', { callback: true, promise: true });
14981509 */
14991510Collection . prototype . options = function ( opts , callback ) {
15001511 if ( typeof opts === 'function' ) ( callback = opts ) , ( opts = { } ) ;
1512+ opts = opts || { } ;
15011513
15021514 return executeOperation ( this . s . topology , options , [ this , opts , callback ] ) ;
15031515} ;
15041516
15051517var 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 ) {
15081519 if ( err ) return handleCallback ( callback , err ) ;
15091520 if ( collections . length === 0 ) {
15101521 return handleCallback (
@@ -1530,6 +1541,7 @@ define.classMethod('options', { callback: true, promise: true });
15301541 */
15311542Collection . prototype . isCapped = function ( options , callback ) {
15321543 if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1544+ options = options || { } ;
15331545
15341546 return executeOperation ( this . s . topology , isCapped , [ this , options , callback ] ) ;
15351547} ;
@@ -1596,6 +1608,7 @@ define.classMethod('createIndex', { callback: true, promise: true });
15961608 */
15971609Collection . prototype . createIndexes = function ( indexSpecs , options , callback ) {
15981610 if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1611+ options = options || { } ;
15991612
16001613 return executeOperation ( this . s . topology , createIndexes , [ this , indexSpecs , options , callback ] ) ;
16011614} ;
@@ -1842,6 +1855,7 @@ define.classMethod('ensureIndex', { callback: true, promise: true });
18421855 */
18431856Collection . prototype . indexExists = function ( indexes , options , callback ) {
18441857 if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1858+ options = options || { } ;
18451859
18461860 return executeOperation ( this . s . topology , indexExists , [ this , indexes , options , callback ] ) ;
18471861} ;
@@ -1939,8 +1953,9 @@ var count = function(self, query, options, callback) {
19391953 if ( hint ) cmd . hint = hint ;
19401954
19411955 options = shallowClone ( options ) ;
1956+
19421957 // 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 ) ;
19441959
19451960 // Do we have a readConcern specified
19461961 if ( self . s . readConcern ) {
@@ -1977,7 +1992,13 @@ Collection.prototype.distinct = function(key, query, options, callback) {
19771992 var queryOption = args . length ? args . shift ( ) || { } : { } ;
19781993 var optionsOption = args . length ? args . shift ( ) || { } : { } ;
19791994
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+ ] ) ;
19812002} ;
19822003
19832004var distinct = function ( self , key , query , options , callback ) {
@@ -2025,6 +2046,7 @@ define.classMethod('distinct', { callback: true, promise: true });
20252046 */
20262047Collection . prototype . indexes = function ( options , callback ) {
20272048 if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
2049+ options = options || { } ;
20282050
20292051 return executeOperation ( this . s . topology , indexes , [ this , options , callback ] ) ;
20302052} ;
@@ -2148,7 +2170,13 @@ Collection.prototype.findOneAndReplace = function(filter, replacement, options,
21482170 if ( replacement == null || typeof replacement !== 'object' )
21492171 throw toError ( 'replacement parameter must be an object' ) ;
21502172
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+ ] ) ;
21522180} ;
21532181
21542182var findOneAndReplace = function ( self , filter , replacement , options , callback ) {
@@ -2192,7 +2220,13 @@ Collection.prototype.findOneAndUpdate = function(filter, update, options, callba
21922220 if ( update == null || typeof update !== 'object' )
21932221 throw toError ( 'update parameter must be an object' ) ;
21942222
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+ ] ) ;
21962230} ;
21972231
21982232var findOneAndUpdate = function ( self , filter , update , options , callback ) {
@@ -2241,7 +2275,14 @@ Collection.prototype.findAndModify = function(query, sort, doc, options, callbac
22412275 // Force read preference primary
22422276 options . readPreference = ReadPreference . PRIMARY ;
22432277
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+ ] ) ;
22452286} ;
22462287
22472288var findAndModify = function ( self , query , sort , doc , options , callback ) {
@@ -2679,7 +2720,8 @@ var geoNear = function(self, x, y, point, options, callback) {
26792720 var exclude = {
26802721 readPreference : true ,
26812722 geoNear : true ,
2682- near : true
2723+ near : true ,
2724+ session : true
26832725 } ;
26842726
26852727 // Filter out any excluded objects
@@ -2736,7 +2778,7 @@ var geoHaystackSearch = function(self, x, y, options, callback) {
27362778 } ;
27372779
27382780 // Remove read preference from hash if it exists
2739- commandObject = decorateCommand ( commandObject , options , { readPreference : true } ) ;
2781+ commandObject = decorateCommand ( commandObject , options , { readPreference : true , session : true } ) ;
27402782
27412783 options = shallowClone ( options ) ;
27422784 // Ensure we have the right read preference inheritance
@@ -3014,7 +3056,7 @@ var mapReduce = function(self, map, reduce, options, callback) {
30143056 } ;
30153057
30163058 // Exclusion list
3017- var exclusionList = [ 'readPreference' ] ;
3059+ var exclusionList = [ 'readPreference' , 'session' ] ;
30183060
30193061 // Add any other options passed in
30203062 for ( var n in options ) {
0 commit comments