Mongodb (v2.4.0) $match aggregate not working with date range

前端 未结 2 864
面向向阳花
面向向阳花 2021-01-14 08:46

I am using mongodb java driver thru maven repository (as below in pom.xml) to query transactions between date range with aggregate framwork. The java driver generates follo

2条回答
  •  礼貌的吻别
    2021-01-14 09:06

    You have to format the date before passing onto $match aggregate.

    Order.aggregate([
            {
              $match: {
                createdAt: {
                  $gte: new Date(req.body.startDate),
                  $lt: new Date(req.body.endDate)
                }
              }
            },
            {
              $lookup: {
                from: 'acbinstallerpayments',
                localField: "_id",
                foreignField: 'customerObjectID',
                as: 'installerPaymentDetails'
              }
            }
          ]);
    

提交回复
热议问题