@@ -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'
@@ -1652,16 +1649,30 @@ export class Collection implements OperationParent {
1652
1649
* @param options - Optional settings for the command
1653
1650
* @param callback - An optional callback, a Promise will be returned if none is provided
1654
1651
*/
1652
+ findAndRemove ( query : Document , callback : Callback ) : void ;
1653
+ findAndRemove ( query : Document , sort : Sort , callback : Callback ) : void ;
1654
+ findAndRemove ( query : Document , options : FindAndModifyOptions , callback : Callback ) : void ;
1655
1655
findAndRemove (
1656
1656
query : Document ,
1657
- sort : Document ,
1657
+ sort : Sort ,
1658
1658
options : FindAndModifyOptions ,
1659
1659
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 ( ) || { } : { } ;
1660
+ ) : void ;
1661
+ findAndRemove ( query : Document ) : Promise < Document > ;
1662
+ findAndRemove ( query : Document , sort : Sort ) : Promise < Document > ;
1663
+ findAndRemove ( query : Document , sort : Sort , options : FindAndModifyOptions ) : Promise < Document > ;
1664
+ findAndRemove (
1665
+ query : Document ,
1666
+ ...args : any [ ]
1667
+ ) : // TODO: Use labeled tuples when api-extractor supports TS 4.0
1668
+ /*sort?: Sort | FindAndModifyOptions | Callback<Document>, */
1669
+ /*options?: FindAndModifyOptions | Callback<Document>, */
1670
+ /*callback?: Callback<Document>*/
1671
+ Promise < Document > | void {
1672
+ const callback =
1673
+ typeof args [ args . length - 1 ] === 'function' ? ( args . pop ( ) as Callback ) : undefined ;
1674
+ const sort = ( args . length ? args . shift ( ) || [ ] : [ ] ) as Sort ;
1675
+ const options = ( args . length ? args . shift ( ) || { } : { } ) as FindAndModifyOptions ;
1665
1676
1666
1677
// Add the remove option
1667
1678
options . remove = true ;
@@ -1687,26 +1698,23 @@ export class Collection implements OperationParent {
1687
1698
* @param callback - An optional callback, a Promise will be returned if none is provided
1688
1699
*/
1689
1700
group (
1701
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
1690
1702
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 ( ) || { } : { } ;
1703
+ condition : Document ,
1704
+ initial : Document ,
1705
+ // TODO: Use labeled tuples when api-extractor supports TS 4.0
1706
+ ...args : [ /*reduce?:*/ any , /*finalize?:*/ any , /*command?:*/ any , /*callback?:*/ Callback ]
1707
+ ) : Promise < Document > | void {
1708
+ const callback = typeof args [ args . length - 1 ] === 'function' ? args . pop ( ) : undefined ;
1709
+ let reduce = args . length ? args . shift ( ) : undefined ;
1710
+ let finalize = args . length ? args . shift ( ) : undefined ;
1711
+ let command = args . length ? args . shift ( ) : undefined ;
1712
+ const options = args . length ? args . shift ( ) || { } : { } ;
1705
1713
1706
1714
// Make sure we are backward compatible
1707
1715
if ( ! ( typeof finalize === 'function' ) ) {
1708
1716
command = finalize ;
1709
- finalize = null ;
1717
+ finalize = undefined ;
1710
1718
}
1711
1719
1712
1720
if (
@@ -1751,7 +1759,7 @@ export class Collection implements OperationParent {
1751
1759
*
1752
1760
* @param query - Query object to locate the object to modify.
1753
1761
* @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.
1762
+ * @param doc - The fields/values to be updated.
1755
1763
* @param options - Optional settings for the command
1756
1764
* @param callback - An optional callback, a Promise will be returned if none is provided
1757
1765
*/
0 commit comments