Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NODE-4684)!: remove collection insert, update, remove methods #3500

Merged
merged 13 commits into from
Jan 11, 2023

Conversation

nbbeeken
Copy link
Contributor

@nbbeeken nbbeeken commented Dec 21, 2022

Description

What is changing?

Removes the legacy crud methods.

What is the motivation for this change?

Modernize code base, remove duplicate code.

Double check the following

TODO:

  • Migration guide
  • Feedback on shimming old methods

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@nbbeeken nbbeeken force-pushed the NODE-4684-rm-coll-insert-update-remove branch 2 times, most recently from d132852 to 672ddc1 Compare January 3, 2023 20:19
@nbbeeken nbbeeken marked this pull request as ready for review January 3, 2023 20:21
@nbbeeken
Copy link
Contributor Author

nbbeeken commented Jan 3, 2023

I collected the usage counts of the legacy methods in this patch.

4.0-replica_set reports: { insert: 326, update: 19, remove: 9 } so I can probably look for the removes and maybe the updates, but the inserts are many 😅

@nbbeeken nbbeeken force-pushed the NODE-4684-rm-coll-insert-update-remove branch from ab21337 to 340565a Compare January 5, 2023 22:23
@nbbeeken
Copy link
Contributor Author

nbbeeken commented Jan 5, 2023

From slack: Looking into search and replace solutions, there wasn't an approach that would make a significant enough impact in the number of insert usages. We'll defer the work to clean this up to a later time

@nbbeeken nbbeeken changed the title feat(NODE-4648)!: remove collection insert, update, remove methods feat(NODE-4684)!: remove collection insert, update, remove methods Jan 5, 2023
@baileympearson baileympearson self-requested a review January 6, 2023 13:41
@baileympearson baileympearson added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Jan 6, 2023
@nbbeeken nbbeeken force-pushed the NODE-4684-rm-coll-insert-update-remove branch from ab2f100 to d73ebba Compare January 6, 2023 18:52
@@ -655,71 +655,6 @@ describe('CRUD API', function () {
}
});

it('should correctly execute remove methods using crud api', {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't using .remove even and is covered by CRUD spec tests

const { expect } = require('chai');
const sinon = require('sinon');
const { setTimeout } = require('timers');
const { Code, ObjectId, Long, Binary, ReturnDocument } = require('../../../src');

describe('Find', function () {
before(function () {
return setupDatabase(this.configuration);
let client;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

introducing mocha hooks cus there was a close leak, classic callback didn't reach the end stuff

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did these leaks only show up now? We didn't change any codepaths so I would expect no change in test behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of those drive by cleanups that I thought we've been trying to do to the tests. There isn't a new persistent leak, it's just when some of the tests in this file were failing with my first pass at doing this work they crash, but in EVG you don't learn about the crash until 20mins later cus of the client that never gets closed. The tests are fixed now so they could continue to create and close the client but we know the hooks provide better DX.

function (err, r) {
// Fetch the id
var id = r.insertedIds[0];
var db = client.db(configuration.db);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leak fix


transactions: transactions
};
var db = client.db(configuration.db);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leak, etc. I'll stop commenting each one

@@ -483,15 +483,6 @@ describe('When executing an operation for the first time', () => {
});
});

describe(`#insert()`, () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to check auto connect on APIs that don't exist

* example-class Collection
* example-method insert
*/
it('Should correctly execute insert with keepGoing option on mongod >= 1.9.1 With Promises', {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keepGoing removed

number_of_tests_done++;
});
});
it('generates new ObjectId for documents without _id property', async function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It failed at first b/c of the insert usage, but then I also cleaned it up cus the setInterval logic was too interesting

test/tools/runner/hooks/legacy.ts Outdated Show resolved Hide resolved
test/tools/runner/hooks/legacy.ts Outdated Show resolved Hide resolved
test/integration/collection-management/collection.test.ts Outdated Show resolved Hide resolved
test/integration/crud/remove.test.js Outdated Show resolved Hide resolved
const { expect } = require('chai');
const sinon = require('sinon');
const { setTimeout } = require('timers');
const { Code, ObjectId, Long, Binary, ReturnDocument } = require('../../../src');

describe('Find', function () {
before(function () {
return setupDatabase(this.configuration);
let client;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did these leaks only show up now? We didn't change any codepaths so I would expect no change in test behavior.

Comment on lines 129 to 141
These legacy methods have been removed. `update` and `remove` invocations are identical to `updateMany` and `deleteMany` respectively.
The `insert` method is equivalent to `insertMany` but the first argument **MUST** be an array.

```ts
// Single document insert:
await collection.insert({ name: 'spot' });
// Migration:
await collection.insertMany([{ name: 'spot' }]);

// Multi-document insert:
await collection.insert([{ name: 'fido' }, { name: 'luna' }])
// Migration:
await collection.insertMany([{ name: 'fido' }, { name: 'luna' }])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a thought - a table that has columns for legacy method / existing crud replacement might be an easier format for users to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was thinking something along the lines of

  • replacing 129-130 with something like "Three legacy crud helpers on the collection class have been removed:"
  • removing the typescript code example
  • putting code examples of before / after in the table, so users clearly see a mapping between the "old code" and "new code"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had code samples when I first wrote the table but it isn't easy to read b/c of how wide it gets, it doesn't get the same scroll effect normal code blocks do. Let me fix up the text part and maybe move the code sample below the table

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed the change, also the bracket are bit hard to notice, "arrayOfDocuments" is obviously just a variable name that implies something. Maybe I should use type annotations instead?

Copy link
Contributor

@W-A-James W-A-James left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the question I had about replacing instances of colllection.insert in tests that are already being modified, lgtm.

test/integration/crud/find.test.js Show resolved Hide resolved
@baileympearson baileympearson merged commit 14427d1 into main Jan 11, 2023
@baileympearson baileympearson deleted the NODE-4684-rm-coll-insert-update-remove branch January 11, 2023 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primary Review In Review with primary reviewer, not yet ready for team's eyes
Projects
None yet
3 participants