如何在节点js中获得mongoose的平均值

时间:2018-01-22 21:46:41

标签: node.js mongodb mongoose average

我创建了这个架构,我想计算去年的平均登录时间

var mongoose = require('mongoose');

var Schema = mongoose.Schema;

var logSchema= new Schema({
     email: {type:String,required:true},
     loginTime: {type:String,required:true},
     loginDate: {type:Date,required:true}
});

var log= mongoose.model('Log',logSchema);

module.exports = log;

我使用此代码,但它不起作用。我可以使用什么

 var Log= require('../models/log');
   function calculateLogTime(time){
    var current_date = new Date();
    var formattedDate = simpleDate.format(current_date, 'dashed');
    Log.average({loginDate:formattedDate},{$avg:'$loginTime'},function(err,count){
        console.log( "Avarage", count );          
        time(count);
     });
}

0 个答案:

没有答案