Such as in stack overflow?
I noticed that some tags are synonyms. For example restaurant and restaurants. Some tags are hierarchical. For example, food -> restaurant.
How do you store the data structure in mongodb?
Do you have sets of synonyms where the default is the id?
Also what would you do if user search for restaurant or restaurants, for example?
Do you convert all search into it’s default form and search the tag or do you expand the search to all of it’s synonym?
What’s the standard way?
I am using mongodb.
The StackOverflow schema is relational. (Specifically MS SQL Server 2008) It maintains a many-to-many relation between Tags and Posts. And it maintains a unidirectional relationship of Tags with their synonyms.
Your restaurants example appears to be a classification system where nodes names in the classification may have synonyms. In this case the data structure of the classification may be more important than the actual node names. How synonym’s are implemented would be highly dependent on the data structure and anticipated query patterns. Look at the Data Modeling Patterns docs to see a variety of different data structures.
Mongo doesn’t have any name aliasing functionality built into the core DB server. Some ORM’s provide a limited name aliasing capability on the client side. For example mongoose through virtual attributes. These should be used with caution though because they don’t provide an underlying performance benefit, and may obscure what’s really happening in the database.