Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 3 additions & 50 deletions mongodb-legacy.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import type {
CountOptions,
CreateCollectionOptions,
CreateIndexesOptions,
CursorCloseOptions,
DbOptions,
DbStatsOptions,
DeleteOptions,
Expand Down Expand Up @@ -69,16 +68,13 @@ import type {
ListDatabasesOptions,
ListDatabasesResult,
ListIndexesOptions,
MapFunction,
MapReduceOptions,
ModifyResult,
MongoClientOptions,
ObjectId,
OperationOptions,
OptionalUnlessRequiredId,
ProfilingLevel,
ProfilingLevelOptions,
ReduceFunction,
RemoveUserOptions,
RenameOptions,
ReplaceOptions,
Expand All @@ -99,7 +95,7 @@ type NonConstructor<T> = Pick<T, NonConstructorKeys<T>>;

declare const Admin: new () => Omit<MDBAdmin, 'addUser' | 'buildInfo' | 'command' | 'listDatabases' | 'ping' | 'removeUser' | 'replSetGetStatus' | 'serverInfo' | 'serverStatus' | 'validateCollection'>;
declare const ChangeStream: new <TSchema extends Document = Document, TChange extends Document = ChangeStreamDocument<TSchema>>() => Omit<MDBChangeStream<TSchema, TChange>, 'close' | 'hasNext' | 'next' | 'tryNext'>;
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'>;
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'>;
declare const Db: new () => Omit<MDBDb, 'command' | 'addUser' | 'removeUser' | 'createCollection' | 'dropCollection' | 'createIndex' | 'dropDatabase' | 'indexInformation' | 'profilingLevel' | 'setProfilingLevel' | 'renameCollection' | 'stats' | 'collections' | 'collection' | 'admin' | 'aggregate' | 'listCollections' | 'watch'>;
declare const GridFSBucket: new (db: LegacyDb, options: GridFSBucketOptions) => Omit<NonConstructor<MDBGridFSBucket>, 'delete' | 'rename' | 'drop' | 'find'>;
declare const MongoClient: new (url: string, options?: MongoClientOptions) => Omit<NonConstructor<MDBMongoClient>, 'connect' | 'close' | 'db' | 'watch' | 'withSession' | 'startSession'>;
Expand Down Expand Up @@ -729,49 +725,6 @@ declare class LegacyCollection<TSchema extends Document = Document> extends Coll
* @typeParam TChange - Type of the whole change stream document emitted
*/
watch<TLocal extends Document = TSchema, TChange extends Document = ChangeStreamDocument<TLocal>>(pipeline?: Document[], options?: ChangeStreamOptions): LegacyChangeStream<TLocal, TChange>;
/**
* Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
*
* @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.
* @param map - The mapping function.
* @param reduce - The reduce function.
* @param options - Optional settings for the command
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
mapReduce<TKey = any, TValue = any>(map: string | MapFunction<TSchema>, reduce: string | ReduceFunction<TKey, TValue>): Promise<Document | Document[]>;
mapReduce<TKey = any, TValue = any>(map: string | MapFunction<TSchema>, reduce: string | ReduceFunction<TKey, TValue>, callback: Callback<Document | Document[]>): void;
mapReduce<TKey = any, TValue = any>(map: string | MapFunction<TSchema>, reduce: string | ReduceFunction<TKey, TValue>, options: MapReduceOptions<TKey, TValue>): Promise<Document | Document[]>;
mapReduce<TKey = any, TValue = any>(map: string | MapFunction<TSchema>, reduce: string | ReduceFunction<TKey, TValue>, options: MapReduceOptions<TKey, TValue>, callback: Callback<Document | Document[]>): void;
/**
* Inserts a single document or a an array of documents into MongoDB. If documents passed in do not contain the **_id** field,
* one will be added to each of the documents missing it by the driver, mutating the document. This behavior
* can be overridden by setting the **forceServerObjectId** flag.
*
* @deprecated Use insertOne, insertMany or bulkWrite instead.
* @param docs - The documents to insert
* @param options - Optional settings for the command
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
insert(docs: OptionalUnlessRequiredId<TSchema>[], options: BulkWriteOptions, callback: Callback<InsertManyResult<TSchema>>): Promise<InsertManyResult<TSchema>> | void;
/**
* Updates documents.
*
* @deprecated use updateOne, updateMany or bulkWrite
* @param selector - The selector for the update operation.
* @param update - The update operations to be applied to the documents
* @param options - Optional settings for the command
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
update(selector: Filter<TSchema>, update: UpdateFilter<TSchema>, options: UpdateOptions, callback: Callback<Document>): Promise<UpdateResult> | void;
/**
* Remove documents.
*
* @deprecated use deleteOne, deleteMany or bulkWrite
* @param selector - The selector for the update operation.
* @param options - Optional settings for the command
* @param callback - An optional callback, a Promise will be returned if none is provided
*/
remove(selector: Filter<TSchema>, options: DeleteOptions, callback: Callback): Promise<DeleteResult> | void;
/**
* An estimated count of matching documents in the db to a filter.
*
Expand Down Expand Up @@ -1111,11 +1064,11 @@ declare class LegacyAbstractCursor<TSchema = any, CursorEvents extends AbstractC
/**
* @deprecated options argument is deprecated
*/
close(options: CursorCloseOptions): Promise<void>;
close(): Promise<void>;
/**
* @deprecated options argument is deprecated
*/
close(options: CursorCloseOptions, callback: Callback): void;
close(callback: Callback): void;
/**
* Returns an array of documents. The caller is responsible for making sure that there
* is enough memory to store the results. Note that the array only contains partial
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This is a wrapper of the `mongodb` driver, if you are starting a new project you
- [Driver Source](https://github.com/mongodb/node-mongodb-native/)
- [Driver NPM Package](https://www.npmjs.com/package/mongodb)

**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)!**

## Purpose

This package is intended to assist in migrating to promise based APIs.
Expand Down
44 changes: 0 additions & 44 deletions src/legacy_wrappers/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,6 @@ module.exports.makeLegacyCollection = function (baseClass) {
return maybeCallback(super.indexes(options), callback);
}

insert(docs, options, callback) {
callback =
typeof callback === 'function'
? callback
: typeof options === 'function'
? options
: undefined;
options = typeof options !== 'function' ? options : undefined;
return maybeCallback(super.insert(docs, options), callback);
}

insertMany(docs, options, callback) {
callback =
typeof callback === 'function'
Expand Down Expand Up @@ -282,17 +271,6 @@ module.exports.makeLegacyCollection = function (baseClass) {
return maybeCallback(super.isCapped(options), callback);
}

mapReduce(map, reduce, options, callback) {
callback =
typeof callback === 'function'
? callback
: typeof options === 'function'
? options
: undefined;
options = typeof options !== 'function' ? options : undefined;
return maybeCallback(super.mapReduce(map, reduce, options), callback);
}

options(options, callback) {
callback =
typeof callback === 'function'
Expand All @@ -304,17 +282,6 @@ module.exports.makeLegacyCollection = function (baseClass) {
return maybeCallback(super.options(options), callback);
}

remove(filter, options, callback) {
callback =
typeof callback === 'function'
? callback
: typeof options === 'function'
? options
: undefined;
options = typeof options !== 'function' ? options : undefined;
return maybeCallback(super.remove(filter, options), callback);
}

rename(newName, options, callback) {
callback =
typeof callback === 'function'
Expand Down Expand Up @@ -351,17 +318,6 @@ module.exports.makeLegacyCollection = function (baseClass) {
return maybeCallback(super.stats(options), callback);
}

update(filter, update, options, callback) {
callback =
typeof callback === 'function'
? callback
: typeof options === 'function'
? options
: undefined;
options = typeof options !== 'function' ? options : undefined;
return maybeCallback(super.update(filter, update, options), callback);
}

updateMany(filter, update, options, callback) {
callback =
typeof callback === 'function'
Expand Down
4 changes: 0 additions & 4 deletions test/tools/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,13 @@ const api = [
{ className: 'Collection', method: 'indexes', returnType: 'Promise<Document[]>' },
{ className: 'Collection', method: 'indexExists', returnType: 'Promise<boolean>' },
{ className: 'Collection', method: 'indexInformation', returnType: 'Promise<Document>' },
{ className: 'Collection', method: 'insert', returnType: 'Promise<InsertManyResult<TSchema>> | void' },
{ className: 'Collection', method: 'insertMany', returnType: 'Promise<InsertManyResult<TSchema>>' },
{ className: 'Collection', method: 'insertOne', returnType: 'Promise<InsertOneResult<TSchema>>' },
{ className: 'Collection', method: 'isCapped', returnType: 'Promise<boolean>' },
{ className: 'Collection', method: 'mapReduce', returnType: 'Promise<Document | Document[]>' },
{ className: 'Collection', method: 'options', returnType: 'Promise<Document>' },
{ className: 'Collection', method: 'remove', returnType: 'Promise<DeleteResult> | void' },
{ className: 'Collection', method: 'rename', returnType: 'Promise<Collection>', changesPromise: true },
{ className: 'Collection', method: 'replaceOne', returnType: 'Promise<UpdateResult | Document>' },
{ className: 'Collection', method: 'stats', returnType: 'Promise<CollStats>' },
{ className: 'Collection', method: 'update', returnType: 'Promise<UpdateResult> | void' },
{ className: 'Collection', method: 'updateMany', returnType: 'Promise<UpdateResult | Document>' },
{ className: 'Collection', method: 'updateOne', returnType: 'Promise<UpdateResult>' },
{ className: 'Collection', method: 'initializeOrderedBulkOp', returnType: 'OrderedBulkOperation', notAsync: true },
Expand Down