ArangoDB 无法从数据集中提取对象值以进行比较或应用筛选器

elcex8rz  于 2022-12-09  发布在  Go
关注(0)|答案(1)|浏览(121)

我尝试在this page上求解Q.22。数据集为here
问题22编写MongoDB查询,查找在众多调查日期中达到“A”级且ISODate“2014-08- 11 T00:00:00 Z”得分为11的餐厅的餐厅ID、名称和等级
数据的格式为:

[
  {
    "_key": "2451925",
    "_id": "restaurants/2451925",
    "_rev": "_buC4Kd2---",
    "address": {
      "building": "1007",
      "coord": [
        -73.856077,
        40.848447
      ],
      "street": "Morris Park Ave",
      "zipcode": "10462"
    },
    "borough": "Bronx",
    "cuisine": "Bakery",
    "grades": [
      {
        "date": {
          "$date": 1393804800000
        },
        "grade": "A",
        "score": 2
      },
      {
        "date": {
          "$date": 1378857600000
        },
        "grade": "A",
        "score": 6
      },
      {
        "date": {
          "$date": 1358985600000
        },
        "grade": "A",
        "score": 10
      },
      {
        "date": {
          "$date": 1322006400000
        },
        "grade": "A",
        "score": 9
      },
      {
        "date": {
          "$date": 1299715200000
        },
        "grade": "B",
        "score": 14
      }
    ],
    "name": "Morris Park Bake Shop",
    "restaurant_id": "30075445"
  },
  {
    "_key": "2451926",
    "_id": "restaurants/2451926",
    "_rev": "_buC4Kd2--A",
    "address": {
      "building": "469",
      "coord": [
        -73.961704,
        40.662942
      ],
      "street": "Flatbush Avenue",
      "zipcode": "11225"
    },
    "borough": "Brooklyn",
    "cuisine": "Hamburgers",
    "grades": [
      {
        "date": {
          "$date": 1419897600000
        },
        "grade": "A",
        "score": 8
      },
      {
        "date": {
          "$date": 1404172800000
        },
        "grade": "B",
        "score": 23
      },
      {
        "date": {
          "$date": 1367280000000
        },
        "grade": "A",
        "score": 12
      },
      {
        "date": {
          "$date": 1336435200000
        },
        "grade": "A",
        "score": 12
      }
    ],
    "name": "Wendy'S",
    "restaurant_id": "30112340"
  }]

我试图过滤掉上面给定的ISODate的日期。我正在使用date_timestamp函数将上面的日期转换为数据中存储日期的方式。
我无法过滤日期,因为它们似乎被包裹在{"$date”:1393804800000}中。在g中尝试一个循环会说找到的是一个对象,而不是一个集合或数组。应用一个过滤器并用date_timestamp()检查是否相等会返回空值数组[],[]等。

for r in restaurants
    for g in r.grades
       let d=date_timestamp("2014-08-11T00:00:00Z")
       return {date:g.date,target_date:d}

请帮忙,谢谢

u5i3ibmn

u5i3ibmn1#

您必须筛选对象内部的字段:

LET target_date = DATE_TIMESTAMP('2014-08-11T00:00:00Z')
FOR r IN restaurants
  FOR g IN r.grades
    FILTER g.date.$date == target_date
    RETURN {date: g.date}

相关问题