简体   繁体   English

Google Datastore节点查询JS中的排序依据和分组依据

[英]Order By and Group By in Google Datastore Node Query JS

I am trying to write a datastore query in NodeJS. 我试图在NodeJS中编写数据存储区查询。

I want to order by timestamp but also only distinct unique ID's (no duplicates) and only retrieve the latest datastore item for each unique ID. 我想按时间戳排序,但也只是不同的唯一ID(没有重复),只检索每个唯一ID的最新数据存储项。


For example 例如

USER_ID - TIMESTAMP
10      - 1000
10      - 500
5       - 10
5       - 1500
5       - 50

I want the query to result with 我希望查询结果

USER_ID - TIMESTAMP
10      - 1000
5       - 1500

What I've tried: 我尝试过的:

datastore.createQuery('example')
  .groupBy('USER_ID')
  .order('USER_ID')
  .order('TIMESTAMP')

But it returns the data ordered by USER_ID , not TIMESTAMP 但它返回USER_ID排序的数据,而不是TIMESTAMP


Here's a pastebin to help answer the question: https://pastebin.com/MQCibmiw 这是一个帮助回答问题的pastebin: https//pastebin.com/MQCibmiw

You'll need to do the sort by timestamp yourself. 您需要自己按时间戳排序。 As previously mentioned, order by USER_ID takes priority, and it's needed because you are running a distinct on query for the grouping. 如前所述,USER_ID的顺序优先,而且需要它,因为您正在对分组运行不同的查询。

As Jim Morrison said, I don't think this is possible. 正如吉姆莫里森所说,我不认为这是可能的。

I filed a Feature Request on your behalf. 我代表您提交了功能请求 Check if my understanding was correct and feel free to add as many details as you think is needed. 检查我的理解是否正确,并随意添加您认为需要的详细信息。

Meanwhile I think the only option you have is to order the TIMESTAMP "manually". 同时我认为你唯一的选择就是“手动”订购TIMESTAMP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM