Home>

I have a question. I wrote the necessary parameters for the scheme (Mongo DB) field, then using the module send:

module.exports= model('Todo', schema);

Exported it, got it in another file

const Todo= require('../models/Todo')

And I now have a find method for Todo (or any others). But at the same time, scheme did not have any such methods, how did it happen that we just exported the variable, and it got new methods?

  • Answer # 1

    It's aboutmodelthis is a function that inside itself makes the Todo model you need and also adds methods for working with the base.

  • Answer # 2

    It's aboutmodelthis is a function that inside itself makes the Todo model you need and also adds methods for working with the base.