【发布时间】:2015-04-29 06:24:08
【问题描述】:
我有一个事件集合,其中包含以这种格式存储的事件日期:YYYY-MM-DD。我想查询所有大于给定日期的事件。这是我目前所拥有的:
var eventSchema = mongoose.Schema({
title : String,
details : String,
start_date : String,
company: {
type: String,
ref: 'Company'
}
});
eventSchema.methods.getUpcomingEvents = function(company_id, cb) {
var date = utils.dateToday(); // returns e.g., '2015-02-26'
return this.model('Event')
.find({ company: company_id, start_date : {$gte: date} })
.sort({start_date: 'asc'})
.exec(function (err, data) {
if (err) {
console.log('ERROR = ' + err);
cb(false, err);
} else {
cb(null, data);
}
})
};
问题是这个查询是返回在提供的“日期”之前发生的事件。我做错了什么?
【问题讨论】: