MongoDB + nodejs : how to query ISODate fields?

后端 未结 4 1866
失恋的感觉
失恋的感觉 2020-12-01 11:58

I am using nodejs with the node-mongodb-native driver (http://mongodb.github.io/node-mongodb-native/).

I have documents with a date property stored as ISODate<

4条回答
  •  臣服心动
    2020-12-01 12:21

    we need to use new Date() is best option to get the data.

    db.getCollection('orders').aggregate([
      {
        '$match': {
          $and: [
            {
              status: 'UNASSIGNED'
            },
            {
              plannedDeliveryDate: {
                '$eq': new Date('2017-10-09')
              }
            }
          ]
        }
      },
      {
        $lookup: {
          from: "servicelocations",
          localField: "serviceLocationId",
          foreignField: "serviceLocationId",
          as: "locations"
        }
      },
      {
        $unwind: "$locations"
      },
      {
        "$project": {
          "accountId": 1,
          "orderId": 1,
          "serviceLocationId": 1,
          "orderDate": 1,
          "description": 1,
          "serviceType": 1,
          "orderSource": 1,
          "takenBy": 1,
          "plannedDeliveryDate": 1,
          "plannedDeliveryTime": 1,
          "actualDeliveryDate": 1,
          "actualDeliveryTime": 1,
          "deliveredBy": 1,
          "size1": 1,
          "size2": 1,
          "size3": 1,
          "jobPriority": 1,
          "cancelReason": 1,
          "cancelDate": 1,
          "cancelBy": 1,
          "reasonCode": 1,
          "reasonText": 1,
          "status": 1,
          "lineItems": 1,
          "locations": {
            "lng": "$locations.location.lng",
            "lat": "$locations.location.lat"
          }
        }
      }
    ])
    

提交回复
热议问题