-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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-5019): add runCursorCommand API #3655
Conversation
ac8cf13
to
acafeb4
Compare
a2bac9d
to
55ecdc6
Compare
fc57254
to
514f8b3
Compare
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.
Partial feedback, need to circle back to finish review
test/spec/unified-test-format/invalid/entity-createRunCursorCommand.json
Outdated
Show resolved
Hide resolved
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.
Reviewed & resolved the addressed comments
await client.close(); | ||
}); | ||
|
||
it('returns each document only once across multiple iterators', async () => { |
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.
Should this test be on AbstractCursor
instead of runCommandCursor
, since the behavior comes from the abstract class? This test is not specific to our RunCommandCursor.
Why was it added now?
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.
The functionality is in the AbstractCursor but as an integration test I'm using the public API to reproduce the expected behavior. I was curious what the behavior of multiple iterators (or nested for-await loops) from one cursor is. Returning a document only once regardless of how many iterators there are is supported by nature of our dequeuing from a List. Since it is a data structure we have changed in the past it is possible that we could modify this behavior if, say, we used an offset into a List that is specific to each iterator.
} catch (e) { | ||
return null; | ||
} | ||
function getChangeStream({ entities, operation }): UnifiedChangeStream | null { |
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.
Could this potentially be a method on the entities
object?
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.
sounds good, moved to entities
const changeStream = getChangeStream({ entities, operation }); | ||
if (changeStream == null) { | ||
// iterateOnce is used for changes streams and regular cursors. | ||
// we have no other way to distinguish which scenario we are testing when we run an | ||
// iterateOnce operation, so we first try to get the changeStream and | ||
// if that fails, we know we need to get a cursor | ||
const cursor = entities.getEntity('cursor', operation.object); | ||
return cursor.tryNext(); | ||
} |
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.
const changeStream = getChangeStream({ entities, operation }); | |
if (changeStream == null) { | |
// iterateOnce is used for changes streams and regular cursors. | |
// we have no other way to distinguish which scenario we are testing when we run an | |
// iterateOnce operation, so we first try to get the changeStream and | |
// if that fails, we know we need to get a cursor | |
const cursor = entities.getEntity('cursor', operation.object); | |
return cursor.tryNext(); | |
} | |
const cursorlike = getChangeStream(..) ?? entities.getEntity('cursor'); | |
return cursorLike.tryNext(); |
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.
same suggestion above
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.
Moved this to a helper on entities
Description
What is changing?
await db.runCursorCommand(command, options)
RunCommandCursor
subclass of AbstractCursorIs there new documentation needed for these changes?
At least API docs for the new command, possibly new docs site page.
What is the motivation for this change?
DRIVERS-2533: mongodb/specifications#1412
Release Highlight
runCursorCommand
APIWe have added the
Db#runCursorCommand
method which can be used to execute generic cursor commands. This API complements the generic Db#command method.Double check the following
npm run check:lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript