我有一个Mongoose查询肯定应该尽我所能,但正在返回undefined
,我无法弄清楚原因。
以下是查询:
...
var perPage = config.perpage;
var page = req.query.page > 0 ? req.query.page : 0;
db.Mail.find().select('-body -scraped').limit(perPage).skip(perPage * page).sort('-createdAt').exec(function (err, mail) {
...
这是以下的架构:
var mongoose = require("mongoose");
var timestamps = require("mongoose-simpletimestamps").SimpleTimestamps;
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
var oneday = 24 * 60 * 60;
var mailSchema = new Schema({
subject: { type: String, required: true },
body: { type: Schema.Types.Mixed, required: true },
status: { type: String, required: true },
processed: {
area: {type: ObjectId, ref: 'Area'},
url: String
},
scraped: { type: Schema.Types.Mixed },
properties: [{ type: ObjectId, ref: 'Property' }],
notifications: [{ type: ObjectId, ref: 'Notification' }],
datestamp: {
type: Number,
default: function () { return Math.floor(Date.now() / oneday ); }
}
});
mailSchema.plugin(timestamps);
module.exports = mongoose.model("Mail", mailSchema);
非常感谢任何帮助,谢谢!