Creating embedded entities with the datastore command line tool

五迷三道 提交于 2019-12-22 12:52:15

问题


I'm trying to use the Google cloud datastore command line interface to create arrays of embedded entities. I've figured out how to create an embedded entity value as follows:

{
    "properties": {
        "age": {
            "integerValue": "5"
        },
        "height": {
            "integerValue": "6"
        }
    }
}

and how to create an array value as follows:

{
    "values": [
        {
            "stringValue": "one"
        },
        {
            "stringValue": "two"
        }
    ]
}

But I haven't figured out how to add an embedded value to an array. For example:

{
    "values": [
        {
            "stringValue": "one"
        },
        {
            "stringValue": "two"
        },
        {
            "embeddedEntityValue": {
                "properties": {
                    "age": {
                        "integerValue": "5"
                    },
                    "height": {
                        "integerValue": "6"
                    }
                }
            }
        }
    ]
}

gives the error: "One or more values in this array doesn't look right. If you include values, make sure they are Datastore array values in JSON format."


回答1:


I believe embeddedEntityValue should be changed to entityValue. Below is an example that shows an Array field with two embedded entities:

{
  "values": [
    {
      "entityValue": {
        "properties": {
          "areaCode": {
            "stringValue": "40"
          },
          "countryCode": {
            "stringValue": "91"
          },
          "subscriberNumber": {
            "stringValue": "2722 5858"
          }
        }
      }
    },
    {
      "entityValue": {
        "properties": {
          "countryCode": {
            "stringValue": "91"
          },
          "subscriberNumber": {
            "stringValue": "6666 0000"
          },
          "areaCode": {
            "stringValue": "80"
          }
        }
      }
    }
  ]
}


来源:https://stackoverflow.com/questions/43739668/creating-embedded-entities-with-the-datastore-command-line-tool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!