【发布时间】:2018-04-08 14:06:51
【问题描述】:
我正在使用restify 和mongodb 和mongoose 编写post api。
'use strict'
const Trending = require('../models/trending');
const trendingController = {
postTrending: (req, res, next)=>{
let data = req.body || {};
console.log(Trending);
let Trending = new Trending(data);
Trending.save(function(err) {
if (err) {
console.log(err)
return next(new errors.InternalError(err.message))
next()
}
res.send(201)
next()
})
}
}
这里的错误是未定义趋势,我不知道为什么.. 其他类似的控制器工作正常。 趋势是猫鼬模型 型号代码
'use strict'
const mongoose = require('mongoose');
const timestamps = require('mongoose-timestamp');
const Schema = mongoose.Schema;
const TrendingSchema = new mongoose.Schema({
_id: Schema.Types.ObjectId,
headline: {
type: String,
required: true
},
description: String,
data: [
{
heading: String,
list: [String]
}
],
tags: [{ type: Schema.Types.ObjectId, ref: 'Tags' }]
});
TrendingSchema.plugin(timestamps);
const Trending = mongoose.model('Trending', TrendingSchema)
module.exports = Trending;
文件夹结构
controllers
--- trending.js
models
---trending.js
【问题讨论】:
-
贴出趋势代码和路径
-
@Sajeetharan 我编辑了帖子
-
你究竟是如何发布你的趋势的?因为我真的看不出你在哪里为此创建了一条路线。
标签: javascript node.js mongoose restify