@@ -45,7 +45,7 @@ import {
45
45
EstimatedDocumentCountOperation ,
46
46
EstimatedDocumentCountOptions
47
47
} from './operations/estimated_document_count' ;
48
- import { FindOperation , FindOptions } from './operations/find' ;
48
+ import { FindOperation , FindOptions , Sort } from './operations/find' ;
49
49
import { FindOneOperation } from './operations/find_one' ;
50
50
import {
51
51
FindAndModifyOperation ,
@@ -126,7 +126,7 @@ export interface CollectionOptions
126
126
127
127
/** @internal */
128
128
export interface CollectionPrivate {
129
- pkFactory : PkFactory | typeof ObjectId ;
129
+ pkFactory : PkFactory ;
130
130
db : Db ;
131
131
topology : Topology ;
132
132
options : any ;
@@ -186,7 +186,9 @@ export class Collection implements OperationParent {
186
186
options,
187
187
topology : db . s . topology ,
188
188
namespace : new MongoDBNamespace ( db . databaseName , name ) ,
189
- pkFactory : db . options ?. pkFactory ? db . options . pkFactory : ObjectId ,
189
+ pkFactory : db . options ?. pkFactory
190
+ ? db . options . pkFactory
191
+ : ( ( ObjectId as unknown ) as PkFactory ) , // TODO: remove when bson is typed
190
192
readPreference : ReadPreference . fromOptions ( options ) ,
191
193
readConcern : ReadConcern . fromOptions ( options ) ,
192
194
writeConcern : WriteConcern . fromOptions ( options ) ,
@@ -213,23 +215,21 @@ export class Collection implements OperationParent {
213
215
214
216
/**
215
217
* The name of the database this collection belongs to
216
- * @readonly
217
218
*/
218
219
get dbName ( ) : string {
219
220
return this . s . namespace . db ;
220
221
}
221
222
222
223
/**
223
224
* The name of this collection
224
- * @readonly
225
225
*/
226
226
get collectionName ( ) : string {
227
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
227
228
return this . s . namespace . collection ! ;
228
229
}
229
230
230
231
/**
231
232
* The namespace of this collection, in the format `${this.dbName}.${this.collectionName}`
232
- * @readonly
233
233
*/
234
234
get namespace ( ) : string {
235
235
return this . s . namespace . toString ( ) ;
@@ -238,7 +238,6 @@ export class Collection implements OperationParent {
238
238
/**
239
239
* The current readConcern of the collection. If not explicitly defined for
240
240
* this collection, will be inherited from the parent DB
241
- * @readonly
242
241
*/
243
242
get readConcern ( ) : ReadConcern | undefined {
244
243
if ( this . s . readConcern == null ) {
@@ -250,7 +249,6 @@ export class Collection implements OperationParent {
250
249
/**
251
250
* The current readPreference of the collection. If not explicitly defined for
252
251
* this collection, will be inherited from the parent DB
253
- * @readonly
254
252
*/
255
253
get readPreference ( ) : ReadPreference | undefined {
256
254
if ( this . s . readPreference == null ) {
@@ -263,7 +261,6 @@ export class Collection implements OperationParent {
263
261
/**
264
262
* The current writeConcern of the collection. If not explicitly defined for
265
263
* this collection, will be inherited from the parent DB
266
- * @readonly
267
264
*/
268
265
get writeConcern ( ) : WriteConcern | undefined {
269
266
if ( this . s . writeConcern == null ) {
@@ -1445,7 +1442,7 @@ export class Collection implements OperationParent {
1445
1442
callback ?: Callback < Document | Document [ ] >
1446
1443
) : Promise < Document | Document [ ] > | void {
1447
1444
if ( 'function' === typeof options ) ( callback = options ) , ( options = { } ) ;
1448
- // Out must allways be defined (make sure we don't break weirdly on pre 1.8+ servers)
1445
+ // Out must always be defined (make sure we don't break weirdly on pre 1.8+ servers)
1449
1446
if ( options ?. out == null ) {
1450
1447
throw new Error (
1451
1448
'the out option parameter must be defined, see mongodb docs for possible values'
@@ -1645,23 +1642,36 @@ export class Collection implements OperationParent {
1645
1642
/**
1646
1643
* Find and remove a document.
1647
1644
*
1648
- * @deprecated use findOneAndDelete instead
1649
- *
1650
1645
* @param query - Query object to locate the object to modify.
1651
1646
* @param sort - If multiple docs match, choose the first one in the specified sort order as the object to manipulate.
1652
1647
* @param options - Optional settings for the command
1653
1648
* @param callback - An optional callback, a Promise will be returned if none is provided
1649
+ * @deprecated use findOneAndDelete instead
1654
1650
*/
1651
+ findAndRemove ( query : Document , callback : Callback ) : void ;
1652
+ findAndRemove ( query : Document , sort : Sort , callback : Callback ) : void ;
1653
+ findAndRemove ( query : Document , options : FindAndModifyOptions , callback : Callback ) : void ;
1655
1654
findAndRemove (
1656
1655
query : Document ,
1657
- sort : Document ,
1656
+ sort : Sort ,
1658
1657
options : FindAndModifyOptions ,
1659
1658
callback : Callback
1660
- ) : Promise < Document > | void {
1661
- const args = Array . prototype . slice . call ( arguments , 1 ) ;
1662
- callback = typeof args [ args . length - 1 ] === 'function' ? args . pop ( ) : undefined ;
1663
- sort = args . length ? args . shift ( ) || [ ] : [ ] ;
1664
- options = args . length ? args . shift ( ) || { } : { } ;
1659
+ ) : void ;
1660
+ findAndRemove ( query : Document ) : Promise < Document > ;
1661
+ findAndRemove ( query : Document , sort : Sort ) : Promise < Document > ;
1662
+ findAndRemove ( query : Document , sort : Sort , options : FindAndModifyOptions ) : Promise < Document > ;
1663
+ findAndRemove (
1664
+ query : Document ,
1665
+ ...args : any [ ]
1666
+ ) : // TODO: Use labeled tuples when api-extractor supports TS 4.0
1667
+ /*sort?: Sort | FindAndModifyOptions | Callback<Document>, */
1668
+ /*options?: FindAndModifyOptions | Callback<Document>, */
1669
+ /*callback?: Callback<Document>*/
1670
+ Promise < Document > | void {
1671
+ const callback =
1672
+ typeof args [ args . length - 1 ] === 'function' ? ( args . pop ( ) as Callback ) : undefined ;
1673
+ const sort = ( args . length ? args . shift ( ) || [ ] : [ ] ) as Sort ;
1674
+ const options = ( args . length ? args . shift ( ) || { } : { } ) as FindAndModifyOptions ;
1665
1675
1666
1676
// Add the remove option
1667
1677
options . remove = true ;
@@ -1687,26 +1697,23 @@ export class Collection implements OperationParent {
1687
1697
* @param callback - An optional callback, a Promise will be returned if none is provided
1688
1698
*/
1689
1699
group (
1700
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1690
1701
keys : any ,
1691
- condition : any ,
1692
- initial : any ,
1693
- reduce : any ,
1694
- finalize : any ,
1695
- command : any ,
1696
- options : any ,
1697
- callback : Callback
1698
- ) {
1699
- const args = Array . prototype . slice . call ( arguments , 3 ) ;
1700
- callback = typeof args [ args . length - 1 ] === 'function' ? args . pop ( ) : undefined ;
1701
- reduce = args . length ? args . shift ( ) : null ;
1702
- finalize = args . length ? args . shift ( ) : null ;
1703
- command = args . length ? args . shift ( ) : null ;
1704
- options = args . length ? args . shift ( ) || { } : { } ;
1702
+ condition : Document ,
1703
+ initial : Document ,
1704
+ // TODO: Use labeled tuples when api-extractor supports TS 4.0
1705
+ ...args : [ /*reduce?:*/ any , /*finalize?:*/ any , /*command?:*/ any , /*callback?:*/ Callback ]
1706
+ ) : Promise < Document > | void {
1707
+ const callback = typeof args [ args . length - 1 ] === 'function' ? args . pop ( ) : undefined ;
1708
+ let reduce = args . length ? args . shift ( ) : undefined ;
1709
+ let finalize = args . length ? args . shift ( ) : undefined ;
1710
+ let command = args . length ? args . shift ( ) : undefined ;
1711
+ const options = args . length ? args . shift ( ) || { } : { } ;
1705
1712
1706
1713
// Make sure we are backward compatible
1707
1714
if ( ! ( typeof finalize === 'function' ) ) {
1708
1715
command = finalize ;
1709
- finalize = null ;
1716
+ finalize = undefined ;
1710
1717
}
1711
1718
1712
1719
if (
@@ -1751,7 +1758,7 @@ export class Collection implements OperationParent {
1751
1758
*
1752
1759
* @param query - Query object to locate the object to modify.
1753
1760
* @param sort - If multiple docs match, choose the first one in the specified sort order as the object to manipulate.
1754
- * @param doc - The fields/vals to be updated.
1761
+ * @param doc - The fields/values to be updated.
1755
1762
* @param options - Optional settings for the command
1756
1763
* @param callback - An optional callback, a Promise will be returned if none is provided
1757
1764
*/
0 commit comments