'Cannot overwrite `categories` model once compiled
** Cannot overwrite categories model once compiled. **
const mongoose = require("mongoose");
const schema = mongoose.Schema;
// create url connect data base
const url = "mongodb://localhost:27017/STOREBOOKS";
// create category for schema
const category = schema({
name: String,
});
// create crcategory in model categores
const Cats = mongoose.model("categoreis", category);
// this function return all categories of Promise
exports.getAllcategories = () => {
return new Promise((resolve, reject) => {
mongoose
.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => Cats.find())
.then((cats) => {
mongoose.disconnect();
resolve(cats);
})
.catch((err) => {
reject(err);
});
});
};
** throw new _mongoose.Error.OverwriteModelError(name);**
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
