I'm writing a few applications that use the same DB and schemas. I need to share the mongoose model between all application- each application has her own express server.
I tried to create a models server and requesting the JSONs useing mongoose-gen npm, it worked but not completely so I have to look for another solution.
I found some answers here about creating an npm package for that, I did so but still, something is missing-I published the package and imported it to my code, but when I actually try to query the schema-nothing is happened, and the server returns 500 with the error:
MongooseError: Operation examples.insertOne()
buffering timed out after 10000ms.
I think that something is missing in my package but I don't know what.
This is what the package includes:
./index.js
const example =require("./SystemWave")
module.exports.Example=example
./SystemWave.js
const mongoose = require('mongoose')
const systenWaveSchema = mongoose.Schema({
timestamp: { type: Date, default: Date.now },
subject: {type:String, require: true},
})
module.exports = mongoose.model('example', systenWaveSchema)
./package.json
{
"name": "modelsnpm",
"version": "1.0.6",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mongoose": "^5.11.15"
}
}
./node_modules
./package-lock.json
./README.md
I don't know if I should add the DB URL or anything else.
Update :
I found another solution here:
Schemas in external module not working in Node.js
but it seems to return the same error...