how to apply date filter on ancestor query

匆匆过客 提交于 2019-12-02 12:11:37

Answering Question 1:

Appengine uses UTC timestamps. Therefor your timestamp is converted from your time zone to UTC. It is still the same date and time though. During output you need to consider that the timestamp may contain the timezone and format / calculate the local time accordingly.

Answering Question 2:

You have all the information you need in your error. If you add

<datastore-index kind="Attendance" ancestor="true" source="manual">
    <property name="date" direction="asc"/>
</datastore-index>

to your datastore-indexes.xml your query should work. If the file doesn't exist yet, create it under src/main/webapp/WEB-INF/datastore-indexes.xml, next to your web.xml and appengine-web.xml files. You can find an example on this page.

As for why: The answer with this error is always: Because datastore requires a composite index for this query.

Just wanted to add to konqi's answer based on comments:

If you are using Cloud Endpoints with Android Studio you must first switch to "project" view in your navigation panel, then navigate to your "backend" folder then src->main->webapp->WEB-INF and then in that folder you must manually create a datastore-indexes.xml file. Here is what yours would look like:

<?xml version="1.0" encoding="utf-8"?>
<datastore-indexes autoGenerate="true">
    <!-- NOTE: Not necessary to create composite indexes here for single property indices b.c. they are build in.-->

    <!-- If you do not specify direction, default is: direction="asc" -->

    <datastore-index kind="Attendance" ancestor="true" source="manual">
        <property name="date" direction="asc"/>
    </datastore-index>

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