@@ -5,7 +5,6 @@ const deprecateOptions = require('./utils').deprecateOptions;
5
5
const checkCollectionName = require ( './utils' ) . checkCollectionName ;
6
6
const ObjectID = require ( './core' ) . BSON . ObjectID ;
7
7
const MongoError = require ( './core' ) . MongoError ;
8
- const toError = require ( './utils' ) . toError ;
9
8
const normalizeHintField = require ( './utils' ) . normalizeHintField ;
10
9
const decorateCommand = require ( './utils' ) . decorateCommand ;
11
10
const decorateWithCollation = require ( './utils' ) . decorateWithCollation ;
@@ -23,7 +22,6 @@ const AggregationCursor = require('./aggregation_cursor');
23
22
const CommandCursor = require ( './command_cursor' ) ;
24
23
25
24
// Operations
26
- const checkForAtomicOperators = require ( './operations/collection_ops' ) . checkForAtomicOperators ;
27
25
const ensureIndex = require ( './operations/collection_ops' ) . ensureIndex ;
28
26
const group = require ( './operations/collection_ops' ) . group ;
29
27
const parallelCollectionScan = require ( './operations/collection_ops' ) . parallelCollectionScan ;
@@ -747,14 +745,6 @@ Collection.prototype.insert = deprecate(function(docs, options, callback) {
747
745
*/
748
746
Collection . prototype . updateOne = function ( filter , update , options , callback ) {
749
747
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
750
- options = options || { } ;
751
-
752
- const err = checkForAtomicOperators ( update ) ;
753
- if ( err ) {
754
- if ( typeof callback === 'function' ) return callback ( err ) ;
755
- return this . s . promiseLibrary . reject ( err ) ;
756
- }
757
-
758
748
options = Object . assign ( { } , options ) ;
759
749
760
750
// Add ignoreUndefined
@@ -763,9 +753,11 @@ Collection.prototype.updateOne = function(filter, update, options, callback) {
763
753
options . ignoreUndefined = this . s . options . ignoreUndefined ;
764
754
}
765
755
766
- const updateOneOperation = new UpdateOneOperation ( this , filter , update , options ) ;
767
-
768
- return executeOperation ( this . s . topology , updateOneOperation , callback ) ;
756
+ return executeOperation (
757
+ this . s . topology ,
758
+ new UpdateOneOperation ( this , filter , update , options ) ,
759
+ callback
760
+ ) ;
769
761
} ;
770
762
771
763
/**
@@ -798,9 +790,11 @@ Collection.prototype.replaceOne = function(filter, doc, options, callback) {
798
790
options . ignoreUndefined = this . s . options . ignoreUndefined ;
799
791
}
800
792
801
- const replaceOneOperation = new ReplaceOneOperation ( this , filter , doc , options ) ;
802
-
803
- return executeOperation ( this . s . topology , replaceOneOperation , callback ) ;
793
+ return executeOperation (
794
+ this . s . topology ,
795
+ new ReplaceOneOperation ( this , filter , doc , options ) ,
796
+ callback
797
+ ) ;
804
798
} ;
805
799
806
800
/**
@@ -826,14 +820,6 @@ Collection.prototype.replaceOne = function(filter, doc, options, callback) {
826
820
*/
827
821
Collection . prototype . updateMany = function ( filter , update , options , callback ) {
828
822
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
829
- options = options || { } ;
830
-
831
- const err = checkForAtomicOperators ( update ) ;
832
- if ( err ) {
833
- if ( typeof callback === 'function' ) return callback ( err ) ;
834
- return this . s . promiseLibrary . reject ( err ) ;
835
- }
836
-
837
823
options = Object . assign ( { } , options ) ;
838
824
839
825
// Add ignoreUndefined
@@ -842,9 +828,11 @@ Collection.prototype.updateMany = function(filter, update, options, callback) {
842
828
options . ignoreUndefined = this . s . options . ignoreUndefined ;
843
829
}
844
830
845
- const updateManyOperation = new UpdateManyOperation ( this , filter , update , options ) ;
846
-
847
- return executeOperation ( this . s . topology , updateManyOperation , callback ) ;
831
+ return executeOperation (
832
+ this . s . topology ,
833
+ new UpdateManyOperation ( this , filter , update , options ) ,
834
+ callback
835
+ ) ;
848
836
} ;
849
837
850
838
/**
@@ -1679,13 +1667,11 @@ Collection.prototype.findOneAndDelete = function(filter, options, callback) {
1679
1667
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1680
1668
options = options || { } ;
1681
1669
1682
- // Basic validation
1683
- if ( filter == null || typeof filter !== 'object' )
1684
- throw toError ( 'filter parameter must be an object' ) ;
1685
-
1686
- const findOneAndDeleteOperation = new FindOneAndDeleteOperation ( this , filter , options ) ;
1687
-
1688
- return executeOperation ( this . s . topology , findOneAndDeleteOperation , callback ) ;
1670
+ return executeOperation (
1671
+ this . s . topology ,
1672
+ new FindOneAndDeleteOperation ( this , filter , options ) ,
1673
+ callback
1674
+ ) ;
1689
1675
} ;
1690
1676
1691
1677
/**
@@ -1714,27 +1700,11 @@ Collection.prototype.findOneAndReplace = function(filter, replacement, options,
1714
1700
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1715
1701
options = options || { } ;
1716
1702
1717
- // Basic validation
1718
- if ( filter == null || typeof filter !== 'object' )
1719
- throw toError ( 'filter parameter must be an object' ) ;
1720
- if ( replacement == null || typeof replacement !== 'object' )
1721
- throw toError ( 'replacement parameter must be an object' ) ;
1722
-
1723
- // Check that there are no atomic operators
1724
- const keys = Object . keys ( replacement ) ;
1725
-
1726
- if ( keys [ 0 ] && keys [ 0 ] [ 0 ] === '$' ) {
1727
- throw toError ( 'The replacement document must not contain atomic operators.' ) ;
1728
- }
1729
-
1730
- const findOneAndReplaceOperation = new FindOneAndReplaceOperation (
1731
- this ,
1732
- filter ,
1733
- replacement ,
1734
- options
1703
+ return executeOperation (
1704
+ this . s . topology ,
1705
+ new FindOneAndReplaceOperation ( this , filter , replacement , options ) ,
1706
+ callback
1735
1707
) ;
1736
-
1737
- return executeOperation ( this . s . topology , findOneAndReplaceOperation , callback ) ;
1738
1708
} ;
1739
1709
1740
1710
/**
@@ -1764,21 +1734,11 @@ Collection.prototype.findOneAndUpdate = function(filter, update, options, callba
1764
1734
if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1765
1735
options = options || { } ;
1766
1736
1767
- // Basic validation
1768
- if ( filter == null || typeof filter !== 'object' )
1769
- throw toError ( 'filter parameter must be an object' ) ;
1770
- if ( update == null || typeof update !== 'object' )
1771
- throw toError ( 'update parameter must be an object' ) ;
1772
-
1773
- const err = checkForAtomicOperators ( update ) ;
1774
- if ( err ) {
1775
- if ( typeof callback === 'function' ) return callback ( err ) ;
1776
- return this . s . promiseLibrary . reject ( err ) ;
1777
- }
1778
-
1779
- const findOneAndUpdateOperation = new FindOneAndUpdateOperation ( this , filter , update , options ) ;
1780
-
1781
- return executeOperation ( this . s . topology , findOneAndUpdateOperation , callback ) ;
1737
+ return executeOperation (
1738
+ this . s . topology ,
1739
+ new FindOneAndUpdateOperation ( this , filter , update , options ) ,
1740
+ callback
1741
+ ) ;
1782
1742
} ;
1783
1743
1784
1744
/**
0 commit comments