I am trying to save the query but It is giving me error cannot overwrite model once compiled. my models file is
const mongoose = require("mongoose")
const history = new mongoose.Schema({
search_name: {
type: String,
required: true,
},
date: {
type: Date,
required: true
}
})
module.exports = mongoose.model("history", history)
and my routes file is:
const keys = require("../config/keys")
const Bing = require('node-bing-api')({ accKey: "0112a649fd944630b0954a20ac8c71f6" });
let History = require("../Models/searchhistory")
module.exports = (app) => {
app.get("/api/imagesearch/:searchname", (req, response) => {
const query = req.params.searchname
const per_page = parseInt(req.query.offset, 10)
Bing.images(query, {
count: 100,
offset: 0
}, (error, res, body) => {
const hist = new History({
})
// hist.save().then(() => {
// })
response.send(body)
})
})
}
I am getting these error when running the code :
F:\image abstraction layer\node_modules\mongoose\lib\index.js:453
throw new _mongoose.Error.OverwriteModelError(name);
^
OverwriteModelError: Cannot overwrite history
model once compiled.
at new OverwriteModelError (F:\image abstraction layer\node_modules\mongoose\lib\error\overwriteModel.js:20:11)
at Mongoose.model (F:\image abstraction layer\node_modules\mongoose\lib\index.js:453:13)
at Object. (F:\image abstraction layer\Models\searchhistory.js:15:27)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18)
at Object. (F:\image abstraction layer\routes\routes.js:3:15)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
[nodemon] app crashed - waiting for file changes before starting...