@@ -1981,14 +1981,16 @@ Collection.prototype.findOneAndDelete = function(filter, options, callback) {
1981
1981
}
1982
1982
1983
1983
var findOneAndDelete = function ( self , filter , options , callback ) {
1984
+ // Final options
1985
+ var finalOptions = shallowClone ( options ) ;
1986
+ finalOptions [ 'fields' ] = options . projection ;
1987
+ finalOptions [ 'remove' ] = true ;
1988
+ // Execute find and Modify
1984
1989
self . findAndModify (
1985
1990
filter
1986
1991
, options . sort
1987
1992
, null
1988
- , {
1989
- fields : options . projection
1990
- , remove :true
1991
- }
1993
+ , finalOptions
1992
1994
, callback
1993
1995
) ;
1994
1996
}
@@ -2030,16 +2032,19 @@ Collection.prototype.findOneAndReplace = function(filter, replacement, options,
2030
2032
}
2031
2033
2032
2034
var findOneAndReplace = function ( self , filter , replacement , options , callback ) {
2035
+ // Final options
2036
+ var finalOptions = shallowClone ( options ) ;
2037
+ finalOptions [ 'fields' ] = options . projection ;
2038
+ finalOptions [ 'update' ] = true ;
2039
+ finalOptions [ 'new' ] = typeof options . returnOriginal == 'boolean' ? ! options . returnOriginal : false ;
2040
+ finalOptions [ 'upsert' ] = typeof options . upsert == 'boolean' ? options . upsert : false ;
2041
+
2042
+ // Execute findAndModify
2033
2043
self . findAndModify (
2034
2044
filter
2035
2045
, options . sort
2036
2046
, replacement
2037
- , {
2038
- fields : options . projection
2039
- , update : true
2040
- , new : typeof options . returnOriginal == 'boolean' ? ! options . returnOriginal : false
2041
- , upsert : typeof options . upsert == 'boolean' ? options . upsert : false
2042
- }
2047
+ , finalOptions
2043
2048
, callback
2044
2049
) ;
2045
2050
}
@@ -2081,16 +2086,19 @@ Collection.prototype.findOneAndUpdate = function(filter, update, options, callba
2081
2086
}
2082
2087
2083
2088
var findOneAndUpdate = function ( self , filter , update , options , callback ) {
2089
+ // Final options
2090
+ var finalOptions = shallowClone ( options ) ;
2091
+ finalOptions [ 'fields' ] = options . projection ;
2092
+ finalOptions [ 'update' ] = true ;
2093
+ finalOptions [ 'new' ] = typeof options . returnOriginal == 'boolean' ? ! options . returnOriginal : false ;
2094
+ finalOptions [ 'upsert' ] = typeof options . upsert == 'boolean' ? options . upsert : false ;
2095
+
2096
+ // Execute findAndModify
2084
2097
self . findAndModify (
2085
2098
filter
2086
2099
, options . sort
2087
2100
, update
2088
- , {
2089
- fields : options . projection
2090
- , update : true
2091
- , new : typeof options . returnOriginal == 'boolean' ? ! options . returnOriginal : false
2092
- , upsert : typeof options . upsert == 'boolean' ? options . upsert : false
2093
- }
2101
+ , finalOptions
2094
2102
, callback
2095
2103
) ;
2096
2104
}
@@ -2178,6 +2186,14 @@ var findAndModify = function(self, query, sort, doc, options, callback) {
2178
2186
// No check on the documents
2179
2187
options . checkKeys = false ;
2180
2188
2189
+ // Get the write concern settings
2190
+ var finalOptions = writeConcern ( options , self . s . db , self , options ) ;
2191
+
2192
+ // Decorate the findAndModify command with the write Concern
2193
+ if ( finalOptions . writeConcern ) {
2194
+ queryObject . writeConcern = finalOptions . writeConcern ;
2195
+ }
2196
+
2181
2197
// Execute the command
2182
2198
self . s . db . command ( queryObject
2183
2199
, options , function ( err , result ) {
0 commit comments