0
votes

I'm using objectify to interact with the datastore from within a GAE endpoint. To save bandwidth I'm trying to only return relevant fields of some entities. On an endpoint rewuest from the client I tried using the setFields() method, but it seems that it is only filtering that on the client, not on the server. The response size stays the same.

Is there any way to only retrieve or send specific fields using either objectify of endpoints?

2

2 Answers

0
votes

A query to the Datastore returns complete entities, with all their properties ("fields"). If you only want to return certain fields, you will need to build the response programmatically. Query, pull desired properties, return.

If you find yourself constantly building subsets of entities, you might want to reconsider your properties in each model. In other words, consider adding some skinnier models, with only the popular properties.

0
votes

You can use Projection queries to pull only a subset of properties for your entities.

https://developers.google.com/appengine/docs/java/datastore/projectionqueries

I don't think that Objectify supports projection queries, so you may have to use a Low-level Datastore API.

An alternative approach is to split your entity into two parts. This may be the way to go, especially if only one of the parts contains frequently updated properties (you will save on writing costs in addition to saving bandwidth).