Existing architecture: nodejs server with mongodb backend.
I have strings coming in describing images that can have #hashtags in them.
I wish to extract the hashtags from the strings, store the hashtags and associate the image with that hashtag.
So e.g. an image is uploaded with 'having fun at #bandcamp #nyc'
#nyc are extracted.
If they don't exist as hashtags already, they're created and the image is associated with them both.
If they do exist, that's recognised and the image is associated with both.
So it will be possible to build a mongo find query that gets all images for a hashtag or multiple hashtags.
I'm new to nosql, I understand that in relational I'd have:
- table hashtags
- table images
- table imageshashtags
with a many to many relationship. An image can have many hash tags, and a hashtag can have many images.
What sort of approach is suitable with mongo? From reading q&a like this: https://stackoverflow.com/questions/8455685/how-to-implement-post-tags-in-mongo
I see that I can implement a sub document in the image document with the tags. Is that efficient for searching and retrieving?
I could then use http://cookbook.mongodb.org/patterns/count_tags/ - map reduce?
So end up with:
images collection withwith tags subdocument tags collection
- images document with tags subdocument with tags extracted and added to it when the image is created, and new tag added to the collection if it's not already present (i.e. tags must be unique)
also create the tag in the tags collection, and run map reduce.
Is that sound? Am I understanding things correctly and is my approach sensible?