在猫鼬中查询并按日期过滤

Querying in mongoose and filtering by dates

我在猫鼬文档中有这个级别

我正在尝试创建一个过滤器来填充某个日期范围内的位置的几何图形。

我尝试这样的事情:

.populate('geometries', null, { 'locations.properties.timeStamp': { $gt: startDate, $lt: endDate }})
.exec(function(err, item) {
//some code
}

像这样:

 .populate('geometries')
 .where({ 'locations.properties.timeStamp': { $gt: startDate, $lt: endDate }}*/)
 .exec(function(err, item) {
    //some code
    }

使用这些查询我无法访问时间戳进行比较,结果为空或未定义。

编辑 1:

变量 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"
            });

并且在 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);
      }
    });
}

这样做:

  var startDate = new Date(request.query.startDate);
  var endDate = new Date(request.query.endDate);

尝试这样做:

.populate({
  path: 'geometries',
  match: { 'locations.properties.timeStamp': { $gt: startDate, $lt: endDate    }},
}).exec()

摘自有关查询条件和其他选项的 mongoose 文档 (http://mongoosejs.com/docs/populate.html)