This is a schema design question; implementation is going to be Mongo, but answers are platform agnostic.
- Given an app, which has users, sessions, and items.
- All visitors will have a session associated with them, but this is a transient row, while user id is associated with them after authentication;
- I want to be able to assign an item to anonymous sessions/users, preferably in a single field, and retain the item association forever.
- Use cases are eg usage data, and survey results; app is heavily interactive, so this schema will interact with most user data on some level
How would you design the item - user - session schema keying?
The design considerations here are: anon user registrates (should merge current anon items with user's items), logs out (should no longer hold the items), logs back again (should merge current anon items, with user's items)
Specifically considered so far:
- keeping the sessions forever, associating items with sessions only, as per this SO answer. I feel this would blow up, as most of the info from a session isn't long-term relevant
- creating a new user for each anonymous session, and keying item to the user (would create lots of empty users);
- keying item to either/or session/user (requires 2 fields)
Any ideas for a clean design?