Multiple select in google datastore query throwing ApiError: Precondition Failed error in node

丶灬走出姿态 提交于 2020-01-16 06:09:59

问题


I'm using following query to retrieve some entities from google Datastore:

var query  = datastore.createQuery(namespace,tableName);
query.select(['displayName','username']);
datastore.getEntitySet(query,function(err,data){
	if(err){
		  res.status(500).end();
	  }
	  else{
		  res.send(data);
	  }
	});

The above code works fine if I select only one property i.e.

query.select('username');

But with multiple select its throwing 412 'Precondition Failed' error. my entity looks like the following: Entity properties


回答1:


You need to create a multi-property index in order to use multi-property queries.

Because you are not using App Engine, these indexes need to be manually created.

I have a tutorial here that covers this.

Here are the steps:

  1. Install Java 7 Runtime (or later version) http://java.com/
    • I recommend using Cloud Shell which has Java already installed and configured
  2. Create a folder called WEB-INF
  3. Inside that folder, you need three files:
    • appengine-web.xml (replace YOUR_PROJECT_ID_HERE with your project ID)
    • web.xml
    • datastore-indexes.xml (Remove the indexes I used for my sample)
  4. In the datastore-indexes.xml file, you need to define your multi-property indexes. Follow the documentation.
  5. Install the gcd tool
  6. Finally, run the gcd tool (one directory above the WEB-INF folder)
    • Linux/Mac path/to/gcd.sh updateindexes --auth_mode=oauth2 .
    • Windows path/to/gcd.cmd updateindexes --auth_mode=oauth2 .

After a few minutes, your indexes should be created.



来源:https://stackoverflow.com/questions/34928582/multiple-select-in-google-datastore-query-throwing-apierror-precondition-failed

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