get 列表数据的时候,data 一直返回 0
来源:11-18 视频列表页对接后台数据
sai1024
2017-11-11
请求成功了,但是返回回来的数据 data 一直是 0,检查了之前是有上传成功的视频啊。请老师和各位同学帮忙看看,或者提供一些思路,谢谢了。
// controller
exports.find = function *(next) {
var page = parseInt(this.query.page, 10) || 1
var count = 5
var offset = (page - 1) * count
var queryArray = [
Creation
.find({finish: 100})
.sort({
'meta.createAt': -1
})
.skip(offset)
.limit(count)
.populate('author', userFields.join(' '))
.exec(),
Creation.count({finish: 100}).exec()
]
var data = yield queryArray
console.log(data)
this.body = {
success: true,
data: data[0],
total: data[1]
}
}// model
var CreationSchema = new Schema({
author: {
type: ObjectId,
ref: 'User'
},
video: {
type: ObjectId,
ref: 'Video'
},
audio: {
type: ObjectId,
ref: 'Audio'
},
qiniu_thumb: String,
qiniu_video: String,
cloudinary_thumb: String,
cloudinary_video: String,
finsh: {
type: Number,
default: 0
},
meta: {
createAt: {
type: Date,
dafault: Date.now()
},
updateAt: {
type: Date,
dafault: Date.now()
}
}
})
CreationSchema.pre('save', function(next) {
if (this.isNew) {
this.meta.createAt = this.meta.updateAt = Date.now()
}
else {
this.meta.updateAt = Date.now()
}
next()
})写回答
4回答
-
Scott
2017-11-18
首先,你的 finsh 在数据里,存的时候,拼错了,应该是 finish
其次,你数据库里的 finish 都是 0,你从外面查询的时候 {finish: 100} 肯定是查不到数据了
10 -
sai1024
提问者
2017-11-15
> db.creations.find({}).pretty() { "_id" : ObjectId("5a06aeaee02006704a95fa4f"), "author" : ObjectId("5a06ad69e02006704a95fa4b"), "audio" : ObjectId("5a06aea2e02006704a95fa4e"), "video" : ObjectId("5a06ae6fe02006704a95fa4d"), "qiniu_thumb" : "video_uwdxcbht7y25mpazsm1y.jpg", "qiniu_video" : "video_uwdxcbht7y25mpazsm1y.mp4", "meta" : { "createAt" : ISODate("2017-11-11T08:02:54.516Z"), "updateAt" : ISODate("2017-11-11T08:02:54.516Z") }, "finsh" : 0, "__v" : 0 } { "_id" : ObjectId("5a06be9f45a880184b56f62d"), "author" : ObjectId("5a06ad69e02006704a95fa4b"), "audio" : ObjectId("5a06be8045a880184b56f62c"), "video" : ObjectId("5a06be6645a880184b56f62b"), "qiniu_thumb" : "video_vzk3twys4rpwquf1i9wt.jpg", "meta" : { "createAt" : ISODate("2017-11-11T09:10:55.460Z"), "updateAt" : ISODate("2017-11-11T09:10:55.460Z") }, "finsh" : 0, "__v" : 0 }00 -
sai1024
提问者
2017-11-14

这是调用 get 请求时的输出
00 -
Scott
2017-11-12
你的 koa 是一代 koa 还是 koa2 啊,如果是一代的话,看看这样改写行不行
var data = yield Promise.all(queryArray)
012017-11-14
相似问题
