vendredi 4 novembre 2022

create only one service for N collection

i am using nestjs with mongoDB. I have a series of collections with different names but with the usual data structure.

we can say that I have N collection where N > 0 and they all have the usual data structure, that is the following:

export class GenericData {
    @Prop()
    email: string;

    @Prop()
    surname: string;

    @Prop()
    name: string;

    _id: string
}

So I have the collection A, B, C, ... with the data structure above.

I wanted to create a single Service that takes care of doing the basic CRUD operations (store, update, find and delete) on the various collections and then save them in a single collection. But I was wondering how to do it.

I didn't want to create an abstract class that then extended other specific classes, but a single service that maybe reads from an ENV the various collections saved in an array that can vary over time

Aucun commentaire:

Enregistrer un commentaire