re: Designing a better architecture for a Node.js API VIEW POST


So I am trying to get the model instance here, but I keep getting cannot overwrite feeds(a model I have) model once compiled. Any help!


I ran some tests some time ago and I realize that when you try to get the model multiple times this error could show up because we try to reinitialize the model.

So a quick fix for that is to add a custom function to your model to get only the model and not reinitialize all of it, like the example below:

getModel() {
return mongoose.model("your model name");

Let me know if that solves your problem. :)


Yes wanted to do this but realized that it will be repeatation of code so I added a functionality to the
getInstance (init =true) {
init && initScheme();
return mongoose.model("your model name");

This is way better, nice job man!
I am going to change the structure of this model soon.

code of conduct - report abuse