rivescripthandlers.js
/*
   * Rivescript subroutine to handle 'subUserRegisterToday'
   */
Rivescript subroutine to handle 'subUserRegisterToday'
Rivescript subroutine to handle ' subUserRegisterToday '
async subUserRegisterToday(rs, args) {
    let dbc = await MongoClient.connect(mongoUrl, { useNewUrlParser: true });
    let db = dbc.db('demo'); 
    let start = new Date()
    let end = new Date()
    start.setHours(0, 0, 0, 0);
    end.setHours(23, 59, 59, 999);
    let colUsers = await db.collection('users');
    let num = await colUsers.countDocuments({
      registered_at: {
        '$gte': start,
        '$lt': end
      }
    });
    dbc.close();
    return `There is ${num} user(s) registered today`;
  }
async subUserRegisterToday ( rs , args ) { let dbc = await MongoClient . connect ( mongoUrl , { useNewUrlParser : true } ) ; let db = dbc . db ( 'demo' ) ; let start = new Date ( ) let end = new Date ( ) start . setHours ( 0 , 0 , 0 , 0 ) ; end . setHours ( 23 , 59 , 59 , 999 ) ; let colUsers = await db . collection ( 'users' ) ; let num = await colUsers . countDocuments ( { registered_at : { '$gte' : start , '$lt' : end } } ) ; dbc . close ( ) ; return ` ${ num } ` ; }
Rivescript subroutine to handle 'subUserRegisterToday'
Rivescript subroutine to handle ' subUserRegisterToday '
// Create a demo database // Mongodb criteria to find how many user register today