无法从数据集中提取对象值以进行比较或对其应用过滤器
Unable to extract object value from dataset to compare or to apply filter on
我正在尝试在 this page. The dataset is here
上解决问题 22
Q.22 编写一个 MongoDB 查询以查找达到“A”等级并在 ISODate“2014-08-11T00”上获得 11 分的餐厅 ID、名称和等级:许多调查日期中的 00:00Z"
数据的形式为:
[
{
"_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() returns 空数组 [],[] 等
是否相等
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}
请帮忙,谢谢
您必须筛选对象内部的字段:
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}
我正在尝试在 this page. The dataset is here
上解决问题 22Q.22 编写一个 MongoDB 查询以查找达到“A”等级并在 ISODate“2014-08-11T00”上获得 11 分的餐厅 ID、名称和等级:许多调查日期中的 00:00Z"
数据的形式为:
[
{
"_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() returns 空数组 [],[] 等
是否相等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}
请帮忙,谢谢
您必须筛选对象内部的字段:
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}