Skip to content

Commit 672ddc1

Browse files
committed
feat(NODE-4648)!: remove collection insert, update, remove methods
1 parent 8900d40 commit 672ddc1

File tree

14 files changed

+324
-610
lines changed

14 files changed

+324
-610
lines changed

etc/notes/CHANGES_5.0.0.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,24 @@ for await (const doc of cursor) {
7171

7272
cursor.closed // true
7373
```
74+
### Removed `Collection.insert`, `Collection.update`, and `Collection.remove`
75+
76+
These legacy methods have been removed. `update` and `remove` invocations are identical to `updateMany` and `deleteMany` respectively.
77+
The `insert` method is equivalent to `insertMany` but the first argument **MUST** be an array.
78+
79+
```ts
80+
// Single document insert:
81+
await collection.insert({ name: 'spot' });
82+
// Migration:
83+
await collection.insertMany([{ name: 'spot' }]);
84+
85+
// Multi-document insert:
86+
await collection.insert([{ name: 'fido' }, { name: 'luna' }])
87+
// Migration:
88+
await collection.insertMany([{ name: 'fido' }, { name: 'luna' }])
89+
```
90+
91+
### Removed `keepGoing` option from `BulkWriteOptions`
92+
93+
The `keepGoing` option was a legacy name for setting `ordered` to `false` for bulk inserts.
94+
It was only supported by the legacy `collection.insert()` method which is now removed as noted above.

src/bulk/common.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,6 @@ export interface BulkWriteOptions extends CommandOperationOptions {
876876
bypassDocumentValidation?: boolean;
877877
/** If true, when an insert fails, don't execute the remaining writes. If false, continue with remaining inserts when one fails. */
878878
ordered?: boolean;
879-
/** @deprecated use `ordered` instead */
880-
keepGoing?: boolean;
881879
/** Force server to assign _id values instead of driver. */
882880
forceServerObjectId?: boolean;
883881
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */

src/collection.ts

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,81 +1634,6 @@ export class Collection<TSchema extends Document = Document> {
16341634
return this.s.db.s.logger;
16351635
}
16361636

1637-
/**
1638-
* Inserts a single document or a an array of documents into MongoDB. If documents passed in do not contain the **_id** field,
1639-
* one will be added to each of the documents missing it by the driver, mutating the document. This behavior
1640-
* can be overridden by setting the **forceServerObjectId** flag.
1641-
*
1642-
* @deprecated Use insertOne, insertMany or bulkWrite instead. Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance
1643-
* @param docs - The documents to insert
1644-
* @param options - Optional settings for the command
1645-
* @param callback - An optional callback, a Promise will be returned if none is provided
1646-
*/
1647-
insert(
1648-
docs: OptionalUnlessRequiredId<TSchema>[],
1649-
options: BulkWriteOptions,
1650-
callback: Callback<InsertManyResult<TSchema>>
1651-
): Promise<InsertManyResult<TSchema>> | void {
1652-
emitWarningOnce(
1653-
'collection.insert is deprecated. Use insertOne, insertMany or bulkWrite instead.'
1654-
);
1655-
if (typeof options === 'function') (callback = options), (options = {});
1656-
options = options || { ordered: false };
1657-
docs = !Array.isArray(docs) ? [docs] : docs;
1658-
1659-
if (options.keepGoing === true) {
1660-
options.ordered = false;
1661-
}
1662-
1663-
return this.insertMany(docs, options, callback);
1664-
}
1665-
1666-
/**
1667-
* Updates documents.
1668-
*
1669-
* @deprecated use updateOne, updateMany or bulkWrite. Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance
1670-
* @param filter - The filter for the update operation.
1671-
* @param update - The update operations to be applied to the documents
1672-
* @param options - Optional settings for the command
1673-
* @param callback - An optional callback, a Promise will be returned if none is provided
1674-
*/
1675-
update(
1676-
filter: Filter<TSchema>,
1677-
update: UpdateFilter<TSchema>,
1678-
options: UpdateOptions,
1679-
callback: Callback<Document>
1680-
): Promise<UpdateResult> | void {
1681-
emitWarningOnce(
1682-
'collection.update is deprecated. Use updateOne, updateMany, or bulkWrite instead.'
1683-
);
1684-
if (typeof options === 'function') (callback = options), (options = {});
1685-
options = options ?? {};
1686-
1687-
return this.updateMany(filter, update, options, callback);
1688-
}
1689-
1690-
/**
1691-
* Remove documents.
1692-
*
1693-
* @deprecated use deleteOne, deleteMany or bulkWrite. Callbacks are deprecated and will be removed in the next major version. See [mongodb-legacy](https://github.com/mongodb-js/nodejs-mongodb-legacy) for migration assistance
1694-
* @param filter - The filter for the remove operation.
1695-
* @param options - Optional settings for the command
1696-
* @param callback - An optional callback, a Promise will be returned if none is provided
1697-
*/
1698-
remove(
1699-
filter: Filter<TSchema>,
1700-
options: DeleteOptions,
1701-
callback: Callback
1702-
): Promise<DeleteResult> | void {
1703-
emitWarningOnce(
1704-
'collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.'
1705-
);
1706-
if (typeof options === 'function') (callback = options), (options = {});
1707-
options = options ?? {};
1708-
1709-
return this.deleteMany(filter, options, callback);
1710-
}
1711-
17121637
/**
17131638
* An estimated count of matching documents in the db to a filter.
17141639
*

0 commit comments

Comments
 (0)