Collection for Y2016W30 (2016-07-25 ~ 2016-08-01)



You can get the id with several ways provided you have the key.
Example with fetch or get:

message = Message.query([0]
message_id =

message = Message.query(
message_id =

If you don't need the entity but only the id then you can save resources by getting only the key.

message_key = Message.query(, keys_only=True)[0]
message_id =

message_key = Message.query(
message_id =

Keep in mind that you can get the key after a put as well:

message_key = message.put()
message_id =


  • GQL Reference|Cloud Datastore|Google Cloud Platform
    • 最近要從 Datastore 裡頭拿資料出來,所以學了一下 GQL 的語法。
    • 基本上跟 SQL 差不多。
    • 但 Datastore 要注意的是,因為其本身是 NoSQL 的結構,所以要做 query 的話,其對應的 condition 必須要有 composite index 才行,所以要更改 index.yaml,並且要 update。一般來說使用官方提供的 GAE SDK 的 這個指令在 local 跑起測試的 GAE server 時,就會順便幫忙檢查,如果有用到新的 index 的話就會自動改寫 index.yaml 了,還算方便。
    • 但要建 composite index 的話,跟該 composite index 相關的所有 columns 都要有 index,否則就無法成功建立,所以建議不要沒事把 datastore 對每個 column 預設開啟的 index 關掉,除非真的確定不會用到 query,否則哪天要加 composite index 的話會很麻煩。





如果覺得這篇文章對你有幫助, 除了留言讓我知道外, 或許也可以考慮請我喝杯咖啡, 不論金額多寡我都會非常感激且能鼓勵我繼續寫出對你有幫助的文章。

If this blog post happens to be helpful to you, besides of leaving a reply, you may consider buy me a cup of coffee to support me. It would help me write more articles helpful to you in the future and I would really appreciate it.

Related Posts