我是node.js的新手。我试图在server.js中创建一个连接并在addAcction.js中使用它但在运行时遇到错误"软件不是 一个构造函数",请帮助我吗?
//Server .js
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/MSDN');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error'));
db.once('open', function callback() {
console.log("Connection with database succeeded.");
});
module.exports = db;
var SoftwareSchema = new mongoose.Schema({
SoftwareID: Number,
SoftwareName: String,
});
module.exports = mongoose.model('Software', SoftwareSchema);
//addAction.js
var Software = require('./Server').Software;
var Software1 = new Software({
SoftwareID : 1,
SoftwareName : "MNG123",
});
Software1.save(function(err){
if ( err ) throw err;
console.log("Software Saved Successfully");
});