[英]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
}
通過這些查詢,我無法訪問timeStamp進行比較,結果為null或未定義。
編輯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);
}
});
}
嘗試這樣做:
.populate({
path: 'geometries',
match: { 'locations.properties.timeStamp': { $gt: startDate, $lt: endDate }},
}).exec()
從貓鼬文檔中提取有關查詢條件和其他選項的信息( http://mongoosejs.com/docs/populate.html )
做這個:
var startDate = new Date(request.query.startDate);
var endDate = new Date(request.query.endDate);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.