新发布版本好像添加标签会报错,有人碰到了吗
D:\test\controllers\tag.js:125
if (tags.length > 0) {
^
TypeError: Cannot read property 'length' of null
at Promise.exports.add (D:\test\controllers\tag.js:125:13)
at Promise.addBack (D:\test\node_modules\mongoose\lib\promise.js:120:8)
at Promise.EventEmitter.emit (events.js:96:17)
at Promise.emit (D:\test\node_modules\mongoose\lib\promise.js:59:38)
at Promise.complete (D:\test\node_modules\mongoose\lib\promise.js:70:20)
at Query.findOne (D:\test\node_modules\mongoose\lib\query.js:876:30)
at exports.tick (D:\test\node_modules\mongoose\lib\utils.js:394:16)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
4 回复
@Jackson 不是版本问题,是源码问题,找到了
Tag.getTagByName(name, function (err, tags) {
if (err) {
return next(err);
}
if (tags.length > 0) {
res.render('notify/notify', {error: '这个标签已存在。'});
return;
}
getTagByName里面使用findOne() 外面判断使用tags.length判断
改下就OK了,
if (tags) {
res.render('notify/notify', {error: '这个标签已存在。'});
return;
}