Skip to content

Commit b18c53e

Browse files
feat!(NODE-4908): drop support for insert, update, remove, mapReduce (#9)
1 parent f69b5fe commit b18c53e

File tree

4 files changed

+5
-98
lines changed

4 files changed

+5
-98
lines changed

mongodb-legacy.d.ts

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import type {
3838
CountOptions,
3939
CreateCollectionOptions,
4040
CreateIndexesOptions,
41-
CursorCloseOptions,
4241
DbOptions,
4342
DbStatsOptions,
4443
DeleteOptions,
@@ -69,16 +68,13 @@ import type {
6968
ListDatabasesOptions,
7069
ListDatabasesResult,
7170
ListIndexesOptions,
72-
MapFunction,
73-
MapReduceOptions,
7471
ModifyResult,
7572
MongoClientOptions,
7673
ObjectId,
7774
OperationOptions,
7875
OptionalUnlessRequiredId,
7976
ProfilingLevel,
8077
ProfilingLevelOptions,
81-
ReduceFunction,
8278
RemoveUserOptions,
8379
RenameOptions,
8480
ReplaceOptions,
@@ -99,7 +95,7 @@ type NonConstructor<T> = Pick<T, NonConstructorKeys<T>>;
9995

10096
declare const Admin: new () => Omit<MDBAdmin, 'addUser' | 'buildInfo' | 'command' | 'listDatabases' | 'ping' | 'removeUser' | 'replSetGetStatus' | 'serverInfo' | 'serverStatus' | 'validateCollection'>;
10197
declare const ChangeStream: new <TSchema extends Document = Document, TChange extends Document = ChangeStreamDocument<TSchema>>() => Omit<MDBChangeStream<TSchema, TChange>, 'close' | 'hasNext' | 'next' | 'tryNext'>;
102-
declare const Collection: new <TSchema>() => Omit<MDBCollection<TSchema>, 'initializeUnorderedBulkOp' | 'initializeOrderedBulkOp' | 'bulkWrite'| 'count'| 'countDocuments'| 'estimatedDocumentCount'| 'createIndex'| 'createIndexes'| 'dropIndex'| 'dropIndexes'| 'deleteMany'| 'deleteOne'| 'distinct'| 'drop'| 'findOne'| 'findOneAndDelete'| 'findOneAndReplace'| 'findOneAndUpdate'| 'indexExists'| 'indexInformation'| 'indexes'| 'insert'| 'insertMany'| 'insertOne'| 'isCapped'| 'mapReduce'| 'options'| 'remove'| 'rename'| 'replaceOne'| 'stats'| 'update'| 'updateMany'| 'updateOne'| 'aggregate'| 'find'| 'listIndexes'| 'watch'>;
98+
declare const Collection: new <TSchema>() => Omit<MDBCollection<TSchema>, 'initializeUnorderedBulkOp' | 'initializeOrderedBulkOp' | 'bulkWrite'| 'count'| 'countDocuments'| 'estimatedDocumentCount'| 'createIndex'| 'createIndexes'| 'dropIndex'| 'dropIndexes'| 'deleteMany'| 'deleteOne'| 'distinct'| 'drop'| 'findOne'| 'findOneAndDelete'| 'findOneAndReplace'| 'findOneAndUpdate'| 'indexExists'| 'indexInformation'| 'indexes'| 'insertMany'| 'insertOne'| 'isCapped'| 'options'| 'rename'| 'replaceOne'| 'stats'| 'updateMany'| 'updateOne'| 'aggregate'| 'find'| 'listIndexes'| 'watch'>;
10399
declare const Db: new () => Omit<MDBDb, 'command' | 'addUser' | 'removeUser' | 'createCollection' | 'dropCollection' | 'createIndex' | 'dropDatabase' | 'indexInformation' | 'profilingLevel' | 'setProfilingLevel' | 'renameCollection' | 'stats' | 'collections' | 'collection' | 'admin' | 'aggregate' | 'listCollections' | 'watch'>;
104100
declare const GridFSBucket: new (db: LegacyDb, options: GridFSBucketOptions) => Omit<NonConstructor<MDBGridFSBucket>, 'delete' | 'rename' | 'drop' | 'find'>;
105101
declare const MongoClient: new (url: string, options?: MongoClientOptions) => Omit<NonConstructor<MDBMongoClient>, 'connect' | 'close' | 'db' | 'watch' | 'withSession' | 'startSession'>;
@@ -732,49 +728,6 @@ declare class LegacyCollection<TSchema extends Document = Document> extends Coll
732728
* @typeParam TChange - Type of the whole change stream document emitted
733729
*/
734730
watch<TLocal extends Document = TSchema, TChange extends Document = ChangeStreamDocument<TLocal>>(pipeline?: Document[], options?: ChangeStreamOptions): LegacyChangeStream<TLocal, TChange>;
735-
/**
736-
* Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
737-
*
738-
* @deprecated collection.mapReduce is deprecated. Use the aggregation pipeline instead. Visit https://docs.mongodb.com/manual/reference/map-reduce-to-aggregation-pipeline for more information on how to translate map-reduce operations to the aggregation pipeline.
739-
* @param map - The mapping function.
740-
* @param reduce - The reduce function.
741-
* @param options - Optional settings for the command
742-
* @param callback - An optional callback, a Promise will be returned if none is provided
743-
*/
744-
mapReduce<TKey = any, TValue = any>(map: string | MapFunction<TSchema>, reduce: string | ReduceFunction<TKey, TValue>): Promise<Document | Document[]>;
745-
mapReduce<TKey = any, TValue = any>(map: string | MapFunction<TSchema>, reduce: string | ReduceFunction<TKey, TValue>, callback: Callback<Document | Document[]>): void;
746-
mapReduce<TKey = any, TValue = any>(map: string | MapFunction<TSchema>, reduce: string | ReduceFunction<TKey, TValue>, options: MapReduceOptions<TKey, TValue>): Promise<Document | Document[]>;
747-
mapReduce<TKey = any, TValue = any>(map: string | MapFunction<TSchema>, reduce: string | ReduceFunction<TKey, TValue>, options: MapReduceOptions<TKey, TValue>, callback: Callback<Document | Document[]>): void;
748-
/**
749-
* Inserts a single document or a an array of documents into MongoDB. If documents passed in do not contain the **_id** field,
750-
* one will be added to each of the documents missing it by the driver, mutating the document. This behavior
751-
* can be overridden by setting the **forceServerObjectId** flag.
752-
*
753-
* @deprecated Use insertOne, insertMany or bulkWrite instead.
754-
* @param docs - The documents to insert
755-
* @param options - Optional settings for the command
756-
* @param callback - An optional callback, a Promise will be returned if none is provided
757-
*/
758-
insert(docs: OptionalUnlessRequiredId<TSchema>[], options: BulkWriteOptions, callback: Callback<InsertManyResult<TSchema>>): Promise<InsertManyResult<TSchema>> | void;
759-
/**
760-
* Updates documents.
761-
*
762-
* @deprecated use updateOne, updateMany or bulkWrite
763-
* @param selector - The selector for the update operation.
764-
* @param update - The update operations to be applied to the documents
765-
* @param options - Optional settings for the command
766-
* @param callback - An optional callback, a Promise will be returned if none is provided
767-
*/
768-
update(selector: Filter<TSchema>, update: UpdateFilter<TSchema>, options: UpdateOptions, callback: Callback<Document>): Promise<UpdateResult> | void;
769-
/**
770-
* Remove documents.
771-
*
772-
* @deprecated use deleteOne, deleteMany or bulkWrite
773-
* @param selector - The selector for the update operation.
774-
* @param options - Optional settings for the command
775-
* @param callback - An optional callback, a Promise will be returned if none is provided
776-
*/
777-
remove(selector: Filter<TSchema>, options: DeleteOptions, callback: Callback): Promise<DeleteResult> | void;
778731
/**
779732
* An estimated count of matching documents in the db to a filter.
780733
*
@@ -1114,11 +1067,11 @@ declare class LegacyAbstractCursor<TSchema = any, CursorEvents extends AbstractC
11141067
/**
11151068
* @deprecated options argument is deprecated
11161069
*/
1117-
close(options: CursorCloseOptions): Promise<void>;
1070+
close(): Promise<void>;
11181071
/**
11191072
* @deprecated options argument is deprecated
11201073
*/
1121-
close(options: CursorCloseOptions, callback: Callback): void;
1074+
close(callback: Callback): void;
11221075
/**
11231076
* Returns an array of documents. The caller is responsible for making sure that there
11241077
* is enough memory to store the results. Note that the array only contains partial

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This is a wrapper of the `mongodb` driver, if you are starting a new project you
77
- [Driver Source](https://github.com/mongodb/node-mongodb-native/)
88
- [Driver NPM Package](https://www.npmjs.com/package/mongodb)
99

10+
**Upgrading to version 5? Take a look at our [upgrade guide here](https://github.com/mongodb/node-mongodb-native/blob/HEAD/etc/notes/CHANGES_5.0.0.md)!**
11+
1012
## Purpose
1113

1214
This package is intended to assist in migrating to promise based APIs.

src/legacy_wrappers/collection.js

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,6 @@ module.exports.makeLegacyCollection = function (baseClass) {
238238
return maybeCallback(super.indexes(options), callback);
239239
}
240240

241-
insert(docs, options, callback) {
242-
callback =
243-
typeof callback === 'function'
244-
? callback
245-
: typeof options === 'function'
246-
? options
247-
: undefined;
248-
options = typeof options !== 'function' ? options : undefined;
249-
return maybeCallback(super.insert(docs, options), callback);
250-
}
251-
252241
insertMany(docs, options, callback) {
253242
callback =
254243
typeof callback === 'function'
@@ -282,17 +271,6 @@ module.exports.makeLegacyCollection = function (baseClass) {
282271
return maybeCallback(super.isCapped(options), callback);
283272
}
284273

285-
mapReduce(map, reduce, options, callback) {
286-
callback =
287-
typeof callback === 'function'
288-
? callback
289-
: typeof options === 'function'
290-
? options
291-
: undefined;
292-
options = typeof options !== 'function' ? options : undefined;
293-
return maybeCallback(super.mapReduce(map, reduce, options), callback);
294-
}
295-
296274
options(options, callback) {
297275
callback =
298276
typeof callback === 'function'
@@ -304,17 +282,6 @@ module.exports.makeLegacyCollection = function (baseClass) {
304282
return maybeCallback(super.options(options), callback);
305283
}
306284

307-
remove(filter, options, callback) {
308-
callback =
309-
typeof callback === 'function'
310-
? callback
311-
: typeof options === 'function'
312-
? options
313-
: undefined;
314-
options = typeof options !== 'function' ? options : undefined;
315-
return maybeCallback(super.remove(filter, options), callback);
316-
}
317-
318285
rename(newName, options, callback) {
319286
callback =
320287
typeof callback === 'function'
@@ -351,17 +318,6 @@ module.exports.makeLegacyCollection = function (baseClass) {
351318
return maybeCallback(super.stats(options), callback);
352319
}
353320

354-
update(filter, update, options, callback) {
355-
callback =
356-
typeof callback === 'function'
357-
? callback
358-
: typeof options === 'function'
359-
? options
360-
: undefined;
361-
options = typeof options !== 'function' ? options : undefined;
362-
return maybeCallback(super.update(filter, update, options), callback);
363-
}
364-
365321
updateMany(filter, update, options, callback) {
366322
callback =
367323
typeof callback === 'function'

test/tools/api.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,13 @@ const api = [
7676
{ className: 'Collection', method: 'indexes', returnType: 'Promise<Document[]>' },
7777
{ className: 'Collection', method: 'indexExists', returnType: 'Promise<boolean>' },
7878
{ className: 'Collection', method: 'indexInformation', returnType: 'Promise<Document>' },
79-
{ className: 'Collection', method: 'insert', returnType: 'Promise<InsertManyResult<TSchema>> | void' },
8079
{ className: 'Collection', method: 'insertMany', returnType: 'Promise<InsertManyResult<TSchema>>' },
8180
{ className: 'Collection', method: 'insertOne', returnType: 'Promise<InsertOneResult<TSchema>>' },
8281
{ className: 'Collection', method: 'isCapped', returnType: 'Promise<boolean>' },
83-
{ className: 'Collection', method: 'mapReduce', returnType: 'Promise<Document | Document[]>' },
8482
{ className: 'Collection', method: 'options', returnType: 'Promise<Document>' },
85-
{ className: 'Collection', method: 'remove', returnType: 'Promise<DeleteResult> | void' },
8683
{ className: 'Collection', method: 'rename', returnType: 'Promise<Collection>', changesPromise: true },
8784
{ className: 'Collection', method: 'replaceOne', returnType: 'Promise<UpdateResult | Document>' },
8885
{ className: 'Collection', method: 'stats', returnType: 'Promise<CollStats>' },
89-
{ className: 'Collection', method: 'update', returnType: 'Promise<UpdateResult> | void' },
9086
{ className: 'Collection', method: 'updateMany', returnType: 'Promise<UpdateResult | Document>' },
9187
{ className: 'Collection', method: 'updateOne', returnType: 'Promise<UpdateResult>' },
9288
{ className: 'Collection', method: 'initializeOrderedBulkOp', returnType: 'OrderedBulkOperation', notAsync: true },

0 commit comments

Comments
 (0)