【发布时间】:2014-05-14 13:11:03
【问题描述】:
当我提交表单请求时,我收到错误 [TypeError: object is not a function]。
这是我的猫鼬代码:hiren-conf.js
var auth = require('../auth.js');
var mongoose = require( 'mongoose' );
mongoose.connect(auth['mongodb']);
var authSchema = new mongoose.Schema({
tag: String,
email: String,
username: String,
createdOn: Date,
updatedOn: { type: Date, default: Date.now },
url: String,
password: String,
icon: String
});
var masterPass = new mongoose.Schema({
hash : String,
tag : String,
state: { type: String, default: false}
});
exports.auth = mongoose.model('Auth', authSchema);
exports.master = mongoose.model('Master', masterPass);
和database.js 代码:
var mongoose = require( 'mongoose' );
var auths = require('../model/hiren-conf');
exports.create = function(req){
var instance = new auths();
if(req.body.tag && req.body.email){
auths.findOne({ 'tag' : req.body.tag , 'email' : req.body.email}, function(err , duplicate){
if (!err){
if(!duplicate){
instance.tag = req.body.tag;
instance.email = req.body.email;
instance.username= req.body.username;
instance.createdOn = Date.now();
instance.url = req.body.url;
instance.password = req.body.password;
instance.save(function(err){
if(!err) console.log('Saved');
});
return "Save";
} else return "Duplicate";
} else console.log(err);
});
}
};
exports.auth 可能有问题,但我不确定。知道如何解决这个问题吗?
【问题讨论】:
-
我猜错误是从
var instance = new auths();内部exports.create抛出的。如果auths是来自hiren-conf.js的exports,那么它将不是function。这将是一个带有auth和master属性的Object。也许试试var instance = new auths.auth();。否则,错误发生在哪一行?堆栈跟踪应包括文件名和行号。 -
也试过了。新错误 TypeError: Object #
-
感谢它现在工作:)
标签: javascript node.js express mongoose