im modeling an app where user can stamps (up to 100 000 stamps).I created the following collections:
users:
{"_id": {"$oid": "xxx" },"email": "test@gmail.com", ...}
stamps:
{"_id": {"$oid": "ccc" },"searchTags": ["tag1", "tag2", "tag3"], ...}
users_stamps
{"_id": {"user": {"$oid": "xxx" },"stamp": {"$oid": "ccc" } },"searchTags": ["tag1", "tag2", "tag3"],}
My goal is to allow users to search stamps in their collection by name (sql equilvalent: "SELECT * FROM stamps WHERE name LIKE "%uru%" and id IN (SELECT stamp_id FROM user_stamps WHERE user_id="xxx")
".
I added "searchTags"
in users_stamps
documents to make fast indexed search on this field.(tried with lookup + condition + filter + limit = too slow as i need to do the lookup on first stage).
Im not sure about this approach so i have some questions:
- Is it ok to do so as when user search for a stamp, i query
stamps
orusers_stamps
depending on user request ? - As
searchTags
is duplicated, is it best to create a DB trigger to updateusers_stamps
each time a stamp is updated (rarely updated) ? - Is this approach good enough for 10k users (10k * 100k stamps= 1billion records on
users_stamps
) ?
Thanks