可以使用MongoDB的聚合管道来实现这个查询条件。

以下是一个示例的聚合管道查询:

db.collection.aggregate([
  {
    $project: {
      dateDiff: {
        $subtract: [
          { $subtract: ["$endDate", "$startDate"] },
          86400000 // 24小时 * 60分钟 * 60秒 * 1000毫秒
        ]
      },
      otherField: 1
    }
  },
  {
    $match: {
      dateDiff: 0,
      otherField: 3
    }
  }
])

在这个示例中,假设你的集合名为 collection,其中包含 startDateendDateotherField 字段。

首先,使用 $project 阶段计算 endDatestartDate 字段的时间差,以毫秒为单位。然后,使用 $match 阶段过滤出时间差为1天(即86400000毫秒)且 otherField 字段等于3的文档。

请根据你的实际集合和字段名称进行适当的调整

mongoDB 以两个时间字段的差集天数=1 和另外一个字段=3 为条件查询数据

原文地址: https://www.cveoy.top/t/topic/h1Tt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录