Skip to content

Instantly share code, notes, and snippets.

@javierfernandes
Last active August 18, 2020 12:08
Show Gist options
  • Select an option

  • Save javierfernandes/e4b80f79becf4ade404ccb16c60a2db6 to your computer and use it in GitHub Desktop.

Select an option

Save javierfernandes/e4b80f79becf4ade404ccb16c60a2db6 to your computer and use it in GitHub Desktop.
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