Open maasencioh opened 2 years ago
I want to create a view of a collection; this usually should be done from a migration.
This is an example of what could be like
import BaseMigration from '@ioc:Zakodium/Mongodb/Migration'; export default class TestMigration extends BaseMigration { public up(): void { this.createView( // Name of the view 'samples.availability', // Origin of view 'samples', // Aggregation pipeline [ { $match: { kind: 'sample' } }, { $group: { _id: { $first: '$parents' }, total: { $sum: 1 }, taken: { $sum: { $cond: ['$meta.reserved', 1, 0] } }, }, }, ], ); } public down(): void { this.deleteView('samples.availability'); } }
Sounds useful. Would you like to do a PR?
I want to create a view of a collection; this usually should be done from a migration.
This is an example of what could be like