错误:3 INVALID_ARGUMENT:无法在 Firestore 管理中转换数组值中的数组值

yas*_*eya 6 javascript arrays firebase google-cloud-firestore

我正在尝试在我的 firstore 数据库中保存使用 twitter api 检索到的多个推文对象,但出现此错误:

错误:3 INVALID_ARGUMENT:无法在数组值中转换数组值

下面是示例JSON对象:所有推文对象都与此类似

TweetObj: {
  "created_at": "Wed Feb 12 15:17:24 +0000 2020",
  "id": 1227612675334660000,
  "id_str": "1227612675334660099",
  "full_text": "Writing online is a superpower.\n\nHere’s a list of people who should start writing online.\n\n1. The Niche Hobbyist\n\nThe Internet rewards people with obscure interests. Writing online will help you find other like-minded hobbyists who you wouldn’t be able to find in real-life.",
  "truncated": false,
  "display_text_range": [
    0,
    274
  ],
  "entities": {
    "hashtags": [],
    "symbols": [],
    "user_mentions": [],
    "urls": []
  },
  "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
  "in_reply_to_status_id": null,
  "in_reply_to_status_id_str": null,
  "in_reply_to_user_id": null,
  "in_reply_to_user_id_str": null,
  "in_reply_to_screen_name": null,
  "user": {
    "id": 240049622,
    "id_str": "240049622",
    "name": "David Perell",
    "screen_name": "david_perell",
    "location": "New York",
    "description": "\"The Writing Guy\" | I tweet about business, online learning, and Internet writing | My Podcast:  | My writing school: ,
    "url": "",
    "entities": {
      "url": {
        "urls": [
          {
            "url": ,
            "expanded_url": "http://www.perell.com/",
            "display_url": "perell.com",
            "indices": [
              0,
              23
            ]
          }
        ]
      },
      "description": {
        "urls": [
          {
            "url": "",
            "expanded_url": "http://Perell.com/podcast",
            "display_url": "Perell.com/podcast",
            "indices": [
              96,
              119
            ]
          },
          {
            "url": "",
            "expanded_url": "http://writeofpassage.school",
            "display_url": "writeofpassage.school",
            "indices": [
              141,
              164
            ]
          }
        ]
      }
    },
    "protected": false,
    "followers_count": 89464,
    "friends_count": 763,
    "listed_count": 1539,
    "created_at": "Wed Jan 19 01:41:27 +0000 2011",
    "favourites_count": 51075,
    "utc_offset": null,
    "time_zone": null,
    "geo_enabled": true,
    "verified": false,
    "statuses_count": 21700,
    "lang": null,
    "contributors_enabled": false,
    "is_translator": false,
    "is_translation_enabled": false,
    "profile_background_color": "C0DEED",
    "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
    "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
    "profile_background_tile": false,
    "profile_image_url": "http://pbs.twimg.com/profile_images/913816689892044800/rF7O3Bfz_normal.jpg",
    "profile_image_url_https": "https://pbs.twimg.com/profile_images/913816689892044800/rF7O3Bfz_normal.jpg",
    "profile_banner_url": "https://pbs.twimg.com/profile_banners/240049622/1543613054",
    "profile_link_color": "129CE6",
    "profile_sidebar_border_color": "C0DEED",
    "profile_sidebar_fill_color": "DDEEF6",
    "profile_text_color": "333333",
    "profile_use_background_image": true,
    "has_extended_profile": true,
    "default_profile": false,
    "default_profile_image": false,
    "following": true,
    "follow_request_sent": false,
    "notifications": true,
    "translator_type": "none"
  },
  "geo": null,
  "coordinates": null,
  "place": {
    "id": "01a9a39529b27f36",
    "url": "https://api.twitter.com/1.1/geo/id/01a9a39529b27f36.json",
    "place_type": "city",
    "name": "Manhattan",
    "full_name": "Manhattan, NY",
    "country_code": "US",
    "country": "United States",
    "contained_within": [],
    "bounding_box": {
      "type": "Polygon",
      "coordinates": [
        [
          [
            -74.026675,
            40.683935
          ],
          [
            -73.910408,
            40.683935
          ],
          [
            -73.910408,
            40.877483
          ],
          [
            -74.026675,
            40.877483
          ]
        ]
      ]
    },
    "attributes": {}
  },
  "contributors": null,
  "is_quote_status": false,
  "retweet_count": 357,
  "favorite_count": 2145,
  "favorited": false,
  "retweeted": false,
  "lang": "en"
}
Run Code Online (Sandbox Code Playgroud)

以上是给出错误的确切对象 在上面的代码片段中,参数threads 是一个array包含多个tweet 对象的对象,就像前面描述的对象一样。

非常感谢帮助。

Mar*_*arc 1

在处理像您这样的复杂 JSON 对象时,我从 Firestore 管理员处收到了完全相同的错误。

问题归结为某些字段包含嵌套数组。在您的情况下三重嵌套,例如您的bounding_box.coordinates 字段。

就我而言,我在将 JSON 对象结构推送到 Firestore 之前将其展平(将嵌套数组转换为简单向量),但您也可以“字符串化”多维数组(使用 JSON.stringify)并将其解析回来(JSON.parse) ) 检索这些特定字段时。