Repository navigation
Conversation
using generators to yield new cursor
Initial $match stage
Necessary in rare case when Mongo strategy is wrong
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
pp0rtal
marked this pull request as ready for review
October 5, 2026 07:45
aurmartin
approved these changes
Oct 5, 2026
| } else { | ||
| const rangeQuery = _.isEmpty(idRange) | ||
| ? query | ||
| : { ...query, _id: idRange }; |
There was a problem hiding this comment.
@pp0rtal This will silently override any _id passed in the query. Should we have a warning or even throw an error in that case? Either here or when validation the options (if there is some kind of validation?), the batchScanSize option is not supported if the query is done on _id.
It's properly handled later 👌
JulienAmoros
approved these changes
Oct 6, 2026
JulienAmoros
left a comment
There was a problem hiding this comment.
Nice!
I spent some time understanding the yield*, but now I get it, very elegant solution 👌
|
|
||
| let treatedDocumentsCount = 0; | ||
| let document = (await cursor.next()) as WithId<TSchema> | null; | ||
| let document = await nextDocument(); |
There was a problem hiding this comment.
[nit] Wouldn't it be better to have a clearer interface for this function?
Suggested change
| let document = await nextDocument(); | |
| let document = await nextDocument(documents); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue: #39
Description
On long MDBM migrations, we can encounter socket timeout. This happens when there are no index (linear scan): Mongodb cursor does not filter out any document for minutes, because docs to update are rare or at the end of a collection. We avoid to create indexes for YOLO migrations.
For those long scans, we'd prefer to fetch by small batch (of 1 million for instance)
We need this as a new option
batchScanSize:Note Camille did this on a migration script code directly here I'm reimplementing the logic to make it a native MBDM feature.
flowchart TD A["find(query)<br/>single cursor"] --> B{"next document?"} B -- yes --> C["update doc / flush bulk"] C --> B B -- no --> D("Finalize last bulk")flowchart TD A["<pre>lower = last upper<br>upper = $gte lower _id + skip(batchScanSize) doc"] A --> C["<pre>find(lower ≤ _id < upper)</pre>(cursor)"] C --> D{"next document?"} D -- yes --> E["update + backup<br/>flush bulk every maxBulkSize"] E --> D D -- no --> F{"upper reached end?"}:::high_blue F -- no --> A F -- yes --> H["flush remaining bulk · end"] classDef high_blue fill:#2567F4,color:#fff,stroke-width:1,stroke:#fffChanges
iterateByIdRanges()whenoptions.batchScanSizeis specified_idalready (merge in$and:[...])options.hint, necessary to specify index now Mongo won't use a perfect matching index