I'm facing problem while doing aggregation in mongoose but reaming all queries are working fine.
service.js file:
service.getAllDeviceRecentLatLng = async (req,res) =>{
try{
let condition = [
{
$match:{clientId: utility.removeQuotationMarks(req.query.clientId)}
},
{
$project:
{
deviceId:1,
recent: { $arrayElemAt: [ "$history", -1 ] }
}
}
];
const deviceTrackingHistory = await DeviceTrackingHistory.getAggregation(condition);
logger.info('sending all DeviceTrackingHistory...');
res.send({success:true, code:200, msg:"sending all DeviceTrackingRecentLatLng", data:deviceTrackingHistory});
}catch(err){
logger.error('Error in getting DeviceTrackingHistory- ' + err);
res.send({success:false, code:500, msg:"sending all DeviceTrackingRecentLatLng Faild", err:err});
}
}
model.js file:
DeviceTrackerHistoryModel.getAggregation = (query) => {
return DeviceTrackerHistoryModel.aggregation(query);
}
Oh! i did wrong in query declaration in my mode.js file, aggregate instead of aggregation.
DeviceTrackerHistoryModel.getAggregation = (query) => {
return DeviceTrackerHistoryModel.aggregate(query);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.