google-cloud-datastore

Executing DISTINCT query with objectify for app engine

旧巷老猫 提交于 2019-12-12 16:45:43
问题 Given the following two tables, how do I write/execute the following query in objectify: SELECT DISTINCT(authorId) FROM Book ORDER BY date DESCENDING LIMIT 30. @Entity Book{ @Id private Long bookId;//auto generated private Key<Author> authorKey; private String title; private Date date; … } @Entity Author{ @Id private Long authorId;//auto generated private String name; … } Note that all I am looking for in my result is a list of authorIds, as in public List<Long> getActiveAuthors(){ ..

How to differentiate whether the code is running in an emulator or in GKE when working with GCP's Datastore

时光毁灭记忆、已成空白 提交于 2019-12-12 16:41:22
问题 I am not sure whether I am missing any, after following the instructions given in https://cloud.google.com/datastore/docs/tools/datastore-emulator I was not able to connect to local emulator unless I create Datastore explicitly using DataStoreClient. DatastoreDb db = DatastoreDb.Create(projectId, string.Empty, new DatastoreClientImpl( new Datastore.DatastoreClient( new Channel("localhost", 8081, ChannelCredentials.Insecure)), new DatastoreSettings())); instead of just DatastoreDb.Create

NDB: Sort query results

可紊 提交于 2019-12-12 15:25:19
问题 In App Engine NDB, I am querying entities that have a repeated property. I would like to order the result by the length of the array representing that property. What I wish I could do: Entity.query(...).order(len(Entity.repeatedProp)) 回答1: You'll need to add an ndb.IntegerProperty() to your entity where you will store the length of the repeated property. Every time you change your repeated property, you'll need to update the stored length. Then you sort based on that stored length. You could

NDB query returns zero results. Datastore shows the result

醉酒当歌 提交于 2019-12-12 15:24:09
问题 I found this peculiar problem where running a Query, confirming the record exists, returns a count of zero. Here are my models: class Description(ndb.Model): description = ndb.TextProperty() time_posted = ndb.DateTimeProperty(auto_now_add=True) uuid = ndb.StringProperty() class Examine(ndb.Model): updated = ndb.DateTimeProperty(auto_now=True, auto_now_add=True) descriptions = ndb.StructuredProperty(Description, repeated=True) active = ndb.KeyProperty(kind=Description) slug = ndb

Google cloud datastore emulator init data

拟墨画扇 提交于 2019-12-12 13:31:13
问题 I would like to use the google cloud datastore emulator for a local project. I have already installed and ran the emulator with : gcloud beta emulators datastore start My app connects to it, but the problem is that I do not know how to fill it with entities since there is no user interface and my application requires some admin users to be present. I also tried to export the production database (datastore) with the following command: gcloud datastore export but couldn't make it work. Should I

Inserting two enties in a transaction & getting 'Cannot operate on different entity groups in a transaction' Error

安稳与你 提交于 2019-12-12 13:17:42
问题 My end goal is simple. I need to have an entity that has two, unique, indexed fields that can operate like keys. If this was a SQL database, the equivelant would be having two fields that are defined as both unique and are independant of one another. I know this functionality isn't directly possible for one data store db.Model, so I've had to create a parent-child Model scenario that mimics this behavior. To solve this problem, I've created two Models (ParentEntity and ChildEntity.) The

Mass updates in Google App Engine Datastore

那年仲夏 提交于 2019-12-12 10:31:49
问题 What is the proper way to perform mass updates on entities in a Google App Engine Datastore? Can it be done without having to retrieve the entities? For example, what would be the GAE equivilant to something like this in SQL: UPDATE dbo.authors SET city = replace(city, 'Salt', 'Olympic') WHERE city LIKE 'Salt%'; 回答1: There isn't a direct translation. The datastore really has no concept of updates; all you can do is overwrite old entities with a new entity at the same address (key). To change

Issue with Google Dataflow using DatastoreIO

故事扮演 提交于 2019-12-12 10:21:53
问题 I'm trying to read a Datastore table with 300k records from Dataflow (DatastoreIO) and getting the following error from Datastore API. 400 Bad Request a composite filter must have at least one sub-filter Code: Query.Builder q = Query.newBuilder(); q.addKindBuilder().setName(options.getKind()); Query query = q.build(); (...) Pipeline p = Pipeline.create(options); p.apply(DatastoreIO.readFrom(options.getDataset(), query).named("ReadFromDatastore"))... Error (happens 4 times before exit): [INFO]

How do I query an appengine datastore with an email address

依然范特西╮ 提交于 2019-12-12 10:14:25
问题 I am trying to lookup users in appengine datastore using their email address. I'm using Go. This code finds no users. var users []entity.User q := datastore.NewQuery("users").Filter("AccountEmail =", "email@address.com") _, err := q.GetAll(c, &users) If I change the query to lookup the user with the "Id" property instead it works fine. var users []entity.User q := datastore.NewQuery("users").Filter("Id", "185804764220139124118") _, err := q.GetAll(c, &users) I've confirmed the property name

Using the App Engine datastore to find overlapping ranges

ぃ、小莉子 提交于 2019-12-12 09:46:47
问题 I'm using Google App Engine for Java with the JDO interface for the datastorage for an application for a CrimeWatch organization. One of the features I'm trying to implement is an away log where people report when they're going to be away for an extended period of time (so the patrols know to keep an eye on the houses). In the app, I have an AwayLogEntry object with a start and end date, and the other fields needed. I need to make a report available to the people who patrol the neighborhood