- Create an Entity with kind "Interest". Have the datastore generate ids automatically for these entities - this will take less space when you reference them from User entities. This entity may have a single property (e.g. "interest" or "text").
When a user enters a new interest, you check if an entity with this interest already exists. If yes, you add an id of this entity to the user's list of interests. If no, you first save a new entity for this interest, and then use the id of this entity.
- Create an Entity with kind "User". This entity will have a property "interests". You can save a collection of ids of interests in this property.
For example, in Java, using a low-level Datastore API, you would do:
public void saveUser(User user) {
Entity userEntity = user.getId() == null ? new Entity("User") : new Entity("User", user.getId());
if (user.getInterests() != null) {
// user.getInterests() returns a collection, e.g. an ArrayList<Long>
userEntity.setProperty("interests", user.getInterests());
}
datastore.put(userEntity);
}
public User getUser(Entity entity) {
User user = new User();
user.setId(entity.getKey().getId());
user.setInterests(entity.getProperty("interests"));
return user;
}
Note that the property "interests" is indexed, so you can run a query to find all users with a specific interest.