@@ -11,9 +11,7 @@ import {
11
11
checkCollectionName ,
12
12
deprecateOptions ,
13
13
executeLegacyOperation ,
14
- MongoDBNamespace ,
15
- handleCallback ,
16
- applyWriteConcern
14
+ MongoDBNamespace
17
15
} from './utils' ;
18
16
import { ObjectId } from './bson' ;
19
17
import { MongoError } from './error' ;
@@ -23,7 +21,7 @@ import ChangeStream = require('./change_stream');
23
21
import WriteConcern = require( './write_concern' ) ;
24
22
import ReadConcern = require( './read_concern' ) ;
25
23
import { AggregationCursor , CommandCursor } from './cursor' ;
26
- import { removeDocuments , updateDocuments , insertDocuments } from './operations/common_functions' ;
24
+ import { removeDocuments , updateDocuments } from './operations/common_functions' ;
27
25
import AggregateOperation = require( './operations/aggregate' ) ;
28
26
import BulkWriteOperation = require( './operations/bulk_write' ) ;
29
27
import CountDocumentsOperation = require( './operations/count_documents' ) ;
@@ -70,7 +68,6 @@ interface Collection {
70
68
insert ( docs : any , options : any , callback : any ) : void ;
71
69
update ( selector : any , update : any , options : any , callback : any ) : void ;
72
70
remove ( selector : any , options : any , callback : any ) : void ;
73
- save ( doc : any , options : any , callback : any ) : void ;
74
71
findOne ( query : any , options : any , callback : any ) : void ;
75
72
dropAllIndexes ( ) : void ;
76
73
ensureIndex ( fieldOrSpec : any , options : any , callback : any ) : void ;
@@ -1455,7 +1452,7 @@ Collection.prototype.find = deprecateOptions(
1455
1452
deprecatedOptions : DEPRECATED_FIND_OPTIONS ,
1456
1453
optionsIndex : 1
1457
1454
} ,
1458
- function ( this : any , query : any , options : any ) {
1455
+ function ( this : any , query : any , options : any ) {
1459
1456
if ( arguments . length > 2 ) {
1460
1457
throw new TypeError ( 'Third parameter to `collection.find()` must be undefined' ) ;
1461
1458
}
@@ -1670,7 +1667,7 @@ Collection.prototype.find = deprecateOptions(
1670
1667
* @returns {Promise<void> } returns Promise if no callback passed
1671
1668
* @deprecated Use insertOne, insertMany or bulkWrite
1672
1669
*/
1673
- Collection . prototype . insert = deprecate ( function (
1670
+ Collection . prototype . insert = deprecate ( function (
1674
1671
this : any ,
1675
1672
docs : any ,
1676
1673
options : any ,
@@ -1710,7 +1707,7 @@ Collection.prototype.insert = deprecate(function(
1710
1707
* @returns {Promise<void> } returns Promise if no callback passed
1711
1708
* @deprecated use updateOne, updateMany or bulkWrite
1712
1709
*/
1713
- Collection . prototype . update = deprecate ( function (
1710
+ Collection . prototype . update = deprecate ( function (
1714
1711
this : any ,
1715
1712
selector : any ,
1716
1713
update : any ,
@@ -1755,7 +1752,7 @@ Collection.prototype.removeMany = Collection.prototype.deleteMany;
1755
1752
* @returns {Promise<void> } returns Promise if no callback passed
1756
1753
* @deprecated use deleteOne, deleteMany or bulkWrite
1757
1754
*/
1758
- Collection . prototype . remove = deprecate ( function (
1755
+ Collection . prototype . remove = deprecate ( function (
1759
1756
this : any ,
1760
1757
selector : any ,
1761
1758
options : any ,
@@ -1779,40 +1776,6 @@ Collection.prototype.remove = deprecate(function(
1779
1776
} ,
1780
1777
'collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.' ) ;
1781
1778
1782
- /**
1783
- * Save a document. Simple full document replacement function. Not recommended for efficiency, use atomic
1784
- * operators and update instead for more efficient operations.
1785
- *
1786
- * @function
1787
- * @param {object } doc Document to save
1788
- * @param {object } [options] Optional settings.
1789
- * @param {(number|string) } [options.w] The write concern.
1790
- * @param {number } [options.wtimeout] The write concern timeout.
1791
- * @param {boolean } [options.j=false] Specify a journal write concern.
1792
- * @param {ClientSession } [options.session] optional session to use for this operation
1793
- * @param {Collection~writeOpCallback } [callback] The command result callback
1794
- * @returns {Promise<void> } returns Promise if no callback passed
1795
- * @deprecated use insertOne, insertMany, updateOne or updateMany
1796
- */
1797
- Collection . prototype . save = deprecate ( function (
1798
- this : any ,
1799
- doc : any ,
1800
- options : any ,
1801
- callback : Function
1802
- ) {
1803
- if ( typeof options === 'function' ) ( callback = options ) , ( options = { } ) ;
1804
- options = options || { } ;
1805
-
1806
- // Add ignoreUndefined
1807
- if ( this . s . options . ignoreUndefined ) {
1808
- options = Object . assign ( { } , options ) ;
1809
- options . ignoreUndefined = this . s . options . ignoreUndefined ;
1810
- }
1811
-
1812
- return executeLegacyOperation ( this . s . topology , save , [ this , doc , options , callback ] ) ;
1813
- } ,
1814
- 'collection.save is deprecated. Use insertOne, insertMany, updateOne, or updateMany instead.' ) ;
1815
-
1816
1779
/**
1817
1780
* The callback format for results
1818
1781
*
@@ -1870,7 +1833,7 @@ Collection.prototype.findOne = deprecateOptions(
1870
1833
deprecatedOptions : DEPRECATED_FIND_OPTIONS ,
1871
1834
optionsIndex : 1
1872
1835
} ,
1873
- function ( this : any , query : any , options : any , callback : Function ) {
1836
+ function ( this : any , query : any , options : any , callback : Function ) {
1874
1837
if ( callback !== undefined && typeof callback !== 'function' ) {
1875
1838
throw new TypeError ( 'Third parameter to `findOne()` must be a callback or undefined' ) ;
1876
1839
}
@@ -1921,7 +1884,7 @@ Collection.prototype.dropAllIndexes = deprecate(
1921
1884
* @param {Collection~resultCallback } [callback] The command result callback
1922
1885
* @returns {Promise<void> } returns Promise if no callback passed
1923
1886
*/
1924
- Collection . prototype . ensureIndex = deprecate ( function (
1887
+ Collection . prototype . ensureIndex = deprecate ( function (
1925
1888
this : any ,
1926
1889
fieldOrSpec : any ,
1927
1890
options : any ,
@@ -1967,7 +1930,7 @@ Collection.prototype.ensureIndex = deprecate(function(
1967
1930
* @returns {Promise<void> } returns Promise if no callback passed
1968
1931
* @deprecated use {@link Collection#countDocuments countDocuments} or {@link Collection#estimatedDocumentCount estimatedDocumentCount} instead
1969
1932
*/
1970
- Collection . prototype . count = deprecate ( function (
1933
+ Collection . prototype . count = deprecate ( function (
1971
1934
this : any ,
1972
1935
query : any ,
1973
1936
options : any ,
@@ -2059,7 +2022,7 @@ function _findAndModify(
2059
2022
* @returns {Promise<void> } returns Promise if no callback passed
2060
2023
* @deprecated use findOneAndDelete instead
2061
2024
*/
2062
- Collection . prototype . findAndRemove = deprecate ( function (
2025
+ Collection . prototype . findAndRemove = deprecate ( function (
2063
2026
this : any ,
2064
2027
query : any ,
2065
2028
sort : any ,
@@ -2099,7 +2062,7 @@ Collection.prototype.findAndRemove = deprecate(function(
2099
2062
* @returns {Promise<void> } returns Promise if no callback passed
2100
2063
* @deprecated MongoDB 3.6 or higher no longer supports the group command. We recommend rewriting using the aggregation framework.
2101
2064
*/
2102
- Collection . prototype . group = deprecate ( function (
2065
+ Collection . prototype . group = deprecate ( function (
2103
2066
this : any ,
2104
2067
keys : any ,
2105
2068
condition : any ,
@@ -2159,36 +2122,4 @@ Collection.prototype.group = deprecate(function(
2159
2122
} ,
2160
2123
'MongoDB 3.6 or higher no longer supports the group command. We recommend rewriting using the aggregation framework.' ) ;
2161
2124
2162
- /**
2163
- * Save a document.
2164
- *
2165
- * @function
2166
- * @param {Collection } coll Collection instance.
2167
- * @param {any } doc Document to save
2168
- * @param {any } [options] Optional settings. See Collection.prototype.save for a list of options.
2169
- * @param {Collection~writeOpCallback } [callback] The command result callback
2170
- * @deprecated use insertOne, insertMany, updateOne or updateMany
2171
- */
2172
- function save ( coll : any , doc : any , options ?: any , callback ?: Function ) {
2173
- // Get the write concern options
2174
- const finalOptions = applyWriteConcern (
2175
- Object . assign ( { } , options ) ,
2176
- { db : coll . s . db , collection : coll } ,
2177
- options
2178
- ) ;
2179
- // Establish if we need to perform an insert or update
2180
- if ( doc . _id != null ) {
2181
- finalOptions . upsert = true ;
2182
- return updateDocuments ( coll , { _id : doc . _id } , doc , finalOptions , callback ) ;
2183
- }
2184
-
2185
- // Insert the document
2186
- insertDocuments ( coll , [ doc ] , finalOptions , ( err ?: any , result ?: any ) => {
2187
- if ( callback == null ) return ;
2188
- if ( doc == null ) return handleCallback ( callback , null , null ) ;
2189
- if ( err ) return handleCallback ( callback , err , null ) ;
2190
- handleCallback ( callback , null , result ) ;
2191
- } ) ;
2192
- }
2193
-
2194
2125
export = Collection ;
0 commit comments