Reputation: 3200
I am moving some of the code from MS SQL to MongoDb. In existing SQLSERVER i have a Profile table , a Tag table and a ProfileTag table. Tag table contains all the available tags and ProfileTag table contains the tags for a specific user.
I need the ability to search Profiles by tags as well as Profile names. So when i design the MongoDB Schema do i still need all 3 classes or can i remove ProfileTag from the list ? I am still trying to wrap my head around the document design.
public class Tag {
}
public class Profile {
public Address Address {get;set;}
public List<Education> EducationList {get;set;}
public List<Tag> ProfileTags {get; set;}
}
Is this the correct approach in designing MongoDB schema ?
Thanks !
Upvotes: 0
Views: 209
Reputation: 4550
As per my experience I think your approach is in correct direction. You do not need the Profile tag as separate collection or class in C#. It can be simple array of strings. In mongodb schema may look like this. In the collection if your profile name is unique you can use it as _id which will be indexed automatically. mongoDB also allow to index the array so you can index on the key like Tags , which will improve the search of profiles based on the Tags. All the generic tags can be hold in another collection. One point you have keep in mind that in case of master tag is updated you have to bulk update all the profile tags as they are embedded in the profile collection
{_id: PROFILENAME , Tags : ["Tag1" , "Tag2" , "Tag3"] }
Upvotes: 1