-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(NODE-4684)!: remove collection insert, update, remove methods #3500
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
Conversation
d132852
to
672ddc1
Compare
I collected the usage counts of the legacy methods in this patch. 4.0-replica_set reports: |
ab21337
to
340565a
Compare
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 |
ab2f100
to
d73ebba
Compare
@@ -655,71 +655,6 @@ describe('CRUD API', function () { | |||
} | |||
}); | |||
|
|||
it('should correctly execute remove methods using crud api', { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()`, () => { |
There was a problem hiding this comment.
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', { |
There was a problem hiding this comment.
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 () { |
There was a problem hiding this comment.
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
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; |
There was a problem hiding this comment.
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.
etc/notes/CHANGES_5.0.0.md
Outdated
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' }]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
Co-authored-by: Bailey Pearson <[email protected]>
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:
npm run check:lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript