如何查询Google Cloud Datastore的数组

时间:2017-04-03 18:22:13

标签: google-cloud-datastore

我已经查询了查询以获取所有事件数据实体列表。结果是谷歌数据存储中的这样。

[{
  "key": {
    "id": 5678669024460800,
    "kind": "Event",
    "path": [
      "Event",
      5678669024460800
    ]
  },
  "data": {
    "createdAt": "2017-03-27T06:28:58.000Z",
    "users":["test1@xxx.com","test2@xxx.com","test3@xxx.com"]
  }
},
{
  "key": {
    "id": 5678669024460800,
    "kind": "Event",
    "path": [
      "Event",
      5678669024460800
    ]
  },
  "data": {
    "createdAt": "2017-03-27T06:28:58.000Z",
    "users":["test1@xxx.com"]
  }
},
{
  "key": {
    "id": 5678669024460800,
    "kind": "Event",
    "path": [
      "Event",
      5678669024460800
    ]
  },
  "data": {
    "createdAt": "2017-03-27T06:28:58.000Z",
    "users":["test2@xxx.com","test3@xxx.com"]
  }
}]

但我需要编写一个查询来过滤电子邮件ID。意味着我需要获取与电子邮件ID匹配的实体。例如,如果我将emailid传递为" test1@xxx.com" ,我应该得到这样的最终结果。任何人都可以帮助我。

[{
  "key": {
    "id": 5678669024460800,
    "kind": "Event",
    "path": [
      "Event",
      5678669024460800
    ]
  },
  "data": {
    "createdAt": "2017-03-27T06:28:58.000Z",
    "users":["test1@xxx.com","test2@xxx.com","test3@xxx.com"]
  }
},
{
  "key": {
    "id": 5678669024460800,
    "kind": "Event",
    "path": [
      "Event",
      5678669024460800
    ]
  },
  "data": {
    "createdAt": "2017-03-27T06:28:58.000Z",
    "users":["test1@xxx.com"]
  }
}]

1 个答案:

答案 0 :(得分:3)

GQL查询类似于 -

SELECT * FROM Event WHERE users='test1@xxx.com' 

您需要确保将users属性编入索引才能使搜索生效,否则您可能无法获得任何结果。