Last active
August 18, 2020 12:08
-
-
Save javierfernandes/e4b80f79becf4ade404ccb16c60a2db6 to your computer and use it in GitHub Desktop.
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
| describeMongoDB('makeBulkMigration()', ({ getDb }) => { | |
| it('should create a migration that process some updates', async () => { | |
| // prepare some data in db | |
| await getDb().collection('tvshows').insertMany([ | |
| { name: 'hello susan', hour: 19 }, | |
| { name: 'another family night', hour: 22 }, | |
| { name: 'abc', hour: 8 }, | |
| { name: 'telefe news', hour: 12 }, | |
| { name: 'tv attacks', hour: 23 }, | |
| ]) | |
| // create and run a migration | |
| const migration = makeBulkMigration({ | |
| collection: 'tvshows', | |
| query: { hour: { $gt: 18 } }, | |
| bulkSize: 2, | |
| bulkItems: updateById('id', set({ night: true })) | |
| }) | |
| await migration(getDb()) | |
| // assert | |
| expect(await getDb().collection('tvshows').find({}).toArray()).toMatchObject([ | |
| { name: 'hello susan', hour: 19, night: true }, // night | |
| { name: 'another family night', hour: 22, night: true }, // night | |
| { name: 'abc', hour: 8 }, | |
| { name: 'telefe news', hour: 12 }, | |
| { name: 'tv attacks', hour: 23, night: true }, // night | |
| ]) | |
| }) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment