adonis-mongodb
adonis-mongodb copied to clipboard
Is it possible to create a view from an aggregation?
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?