收藏
回答

aggregate聚合有时有值,有时就是null,时好时坏?

const $ = db.command.aggregate



else if (event.a == 5{ //使用

    try {

      return await db.collection('chatmsg').aggregate().match({

        fromopenId: event.fromopenId,

      }).orderBy('time','desc').group({    //根据时间降序,取最近100用户数据

        _id: {  

          toopenId: '$toopenId',

          toavatar: '$toavatar',

          tonickName: '$tonickName',

          tosex: '$tosex',     

        },   

        readstate: $.sum('$readstate'),

        time: $.last('$time'), 

        content: $.last('$content'), 

        }).end()

    } catch (e{

      console.log(e)

    }

  } 


回答关注问题邀请回答
收藏

1 个回答

  • 彭为伟
    彭为伟
    2022-06-07

    orderBy('time','desc'). 不能用这个,用这个就会出问题。

    2022-06-07
    有用
    回复
登录 后发表内容