Google App Engine Datastore: How to get entity by ID/Name if parent key is unknown?

10,356

Solution 1

You can't. Parent key is part of the entity key and you need a full key to get an entity.

Also query with key filter won't find entities with parents unless you specify the ancestor key.

Solution 2

If you create all of your "User" entities under a "Root" entity and add a "uuid" property to your "Trip" entity, you can look for the single "Trip" with the specified UUID.

Filter uuidFilter = new FilterPredicate("uuid", FilterOperator.EQUAL, uuid.toString());
Query q = new Query("Trip").setAncestor(root.getKey()).setFilter(uuidFilter);
Share:
10,356
Kappa Leonis
Author by

Kappa Leonis

Updated on June 19, 2022

Comments

  • Kappa Leonis
    Kappa Leonis almost 2 years

    There are two kinds of entity: User and Trip. User is parent to Trip and Trip is child to User.

    For privacy consideration I am POSTing only Trip ID/Name. Because it is looks like a Trip Key contains encoded User ID/Name.

    How to get entity by ID/Name if parent key is unknown?