[英]Querying in mongoose and filtering by dates
I have this levels in mongoose documents 我在猫鼬文件中有这个等级
I'm trying to make a filter to populate the geometry for the locations that are in the range of some date. 我正在尝试创建一个过滤器,以填充某个日期范围内的位置的几何图形。
I try something like this: 我尝试这样的事情:
.populate('geometries', null, { 'locations.properties.timeStamp': { $gt: startDate, $lt: endDate }})
.exec(function(err, item) {
//some code
}
And like this: 像这样:
.populate('geometries')
.where({ 'locations.properties.timeStamp': { $gt: startDate, $lt: endDate }}*/)
.exec(function(err, item) {
//some code
}
With these query I can not access the timeStamp to compare, and the result is null or undefined. 通过这些查询,我无法访问timeStamp进行比较,结果为null或未定义。
EDIT 1: 编辑1:
The variables, startDate and endDate comes in the url from angulars controller, they are defined like this: 变量startDate和endDate来自angulars控制器的url中,它们的定义如下:
var deductDate = new Date(endDate);
var startDate = deductDate.setDate(deductDate.getDate()-1);
Item.currentDay($stateParams.epc, url, {
groupBy: '1d',
endDate: moment(endDate).format(),
startDate: moment(startDate).format('YYYY-MM-DD') + "T23:59:59"
});
And in the API the GET route that handles that is: 在API中,处理的GET路由为:
handler: function(request, reply) {
var startDate = request.query.startDate;
var endDate = request.query.endDate;
Item.findById(request.params.id)
.populate('geometries', null, { 'locations.properties.timeStamp': { $gt: startDate, $lt: endDate }})
.exec(function(err, item) {
if (err) {
reply(err);
} else {
reply(item);
}
});
}
Try to do this: 尝试这样做:
.populate({
path: 'geometries',
match: { 'locations.properties.timeStamp': { $gt: startDate, $lt: endDate }},
}).exec()
Extracted from mongoose documentation about Query conditions and other options ( http://mongoosejs.com/docs/populate.html ) 从猫鼬文档中提取有关查询条件和其他选项的信息( http://mongoosejs.com/docs/populate.html )
Do this: 做这个:
var startDate = new Date(request.query.startDate);
var endDate = new Date(request.query.endDate);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.