Question

I have generated endpoints methods:get,list,remove,update.But what if i have collection of objects that i want to insert,is it only way -insert in loop, or exists solution of bulk insert in AppEngine?

Was it helpful?

Solution

You will have to look at alternate strategies to load data into your application. The reason is that there could be hundreds / thousands of records that you want to do insert as part of your bulk insert.

Now having said that, you could look at the following approach with Cloud Endpoints:

  1. Considering uploading a file (CSV , JSON , XML) to your endpoint API Method. This file will have multiple records that you want to insert.
  2. Process the file in your Endpoint @APIMethod implementation. Process each record and insert them accordingly.

While the above is achievable .. you have to consider the fact that a client has made this API call and is waiting for the response. So if you are going to end up processing multiple records (insert) and then throw back the response, things could time out quickly and also it is not best practices to make the API client wait.

So I suggest that while there are ways to do it via the API, you should look at various alternatives to get the data into your App Engine app. In case you really have to do the File thing, consider accepting the file and throwing back an ACCEPT Response. You could then use a Task Queue on the App Engine to process the file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top