MongoDB嵌入式搜索

斯科蒂

我正在尝试为“ scheduledTimeLocal”进行比赛,仅适用于出发时间。我正在使用以下查询:

db.schedule.find( { "departures.scheduledTimeLocal" : /2020-05-09/})

那没有用,而且似乎也太简单了……所以我尝试使用嵌套的$ elemMatch并搜索完全匹配:

db.schedule.find({'departures':{$elemMatch:{$elemMatch:{$in:['2020-05-09 06:05+01:00']}}}})

但是我都没有得到任何结果。以下是文档中数据的结构:

任何想法表示赞赏。

    { "_id" : ObjectId("5eb5a71731da45610ce0a335"),
      "departures": [
         {
          "movement": {
            "airport": {
             "icao": "LEMG",
             "iata": "AGP",
             "name": "Málaga"
            },
            "scheduledTimeLocal": "2020-05-09 10:40+01:00",
            "scheduledTimeUtc": "2020-05-09 09:40Z",
            "quality": [
              "Basic"
            ]
          },
          "number": "FR 8008",
          "status": "Unknown",
          "codeshareStatus": "Unknown",
          "isCargo": false,
          "aircraft": {
            "model": "Boeing 737-800"
           },
          "airline": {
            "name": "Ryanair"
          }
        },
        {
          "movement": {
            "airport": {
              "icao": "EGLL",
              "iata": "LHR",
              "name": "London"
            },
            "scheduledTimeLocal": "2020-05-09 10:55+01:00",
            "scheduledTimeUtc": "2020-05-09 09:55Z",
            "quality": [
              "Basic"
            ]
          },
          "number": "BA 1307",
          "status": "Unknown",
          "codeshareStatus": "IsOperator",
          "isCargo": false,
          "aircraft": {
            "model": "Airbus A319"
          },
          "airline": {
            "name": "British Airways"
          }
        }
      ],
      "arrivals": [
        {
          "movement": {
            "airport": {
              "icao": "EIDW",
              "iata": "DUB",
              "name": "Dublin"
            },
            "scheduledTimeLocal": "2020-05-09 08:40+01:00",
            "scheduledTimeUtc": "2020-05-09 07:40Z",
            "quality": [
              "Basic"
            ]
          },
          "number": "EI 3240",
          "status": "CanceledUncertain",
          "codeshareStatus": "Unknown",
          "isCargo": false,
          "aircraft": {
            "model": "ATR 72"
          },
          "airline": {
            "name": "Aer Lingus"
          }
        }
      ]
    }
卡希纳特·佩特卡

您可以使用以下查询:

db.getCollection('schedule').find({
     'departures.movement.scheduledTimeLocal' : "2020-05-09 10:40+01:00"
})

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章