收藏
回答

云开发的数据库 group后的数据怎么建立索引?



表结构:

{
    "_id": "14139e1261001208004a2a434b330a9c",
    "created": "2021-07-27T14:02:48.598Z",
    "createdMS": 1627394568333,
    "createdStr": "2021-07-27 22:02:48",
    "gas": "0",
    "mobile": "188000000000",
    "openid": "2898364888888",
    "modified": "2021-07-27T14:02:54.229Z",
    "modifiedMS": 1627394574216,
    "modifiedStr": "2021-07-27 22:02:54",
    "payType": "WXMINI",
    "price": 1,
    "priceBeforeDiscount": 1,
    "priceBeforeDiscountYuan": "0.01",
    "priceYuan": "0.01",
    "printer": "550112792",
    "sfid": 100401,
    "sfname": "柜台",
    "sid": 1004,
    "sname": "奇点风暴加油站",
    "status": "YIZHIFU",
    "wxOrder": "QDPAY1621111672020"
  },


这是查询语句:

const res = await db.collection('order').aggregate().match({
    status: 'YIZHIFU',
    modifiedMS: _.and(_.gte(lastMonthStartMS), _.lte(lastMonthEndMS))
  }).project({
    _id: 0,
    sid: 1,
    mobile: 1,
    openid: 1,
  })
    .group({
      _id: {
        sid: '$sid',// 1
        mobile: '$mobile',// 1
        openid: '$openid',// 1
      },
      ordertimes: $.sum(1),
    })
    .match({
      ordertimes: _.gte(size)// 2
    })
    .end()


1、2那边怎么建索引呢?查询好慢


回答关注问题邀请回答
收藏
登录 后发表内容