Home:ALL Converter>What is a correct mongodb collection structure for full-text search?

What is a correct mongodb collection structure for full-text search?

Ask Time:2015-01-02T14:37:02         Author:grigoryvp

Json Formatter

I have a simple MongoDB website where dedicated search engine (like elasticsearch) will be an overkill and will add support complexity, so I want to stick with MongoDB 2.6 full text search. As i can see, MongoDB llimits text search index to only one field per collection. If I have a Users collection with and want to enable full text search for both user name and user description, what is a correct collection structure for this? I can suggest to create a separate Text collection where I will keep all text information for my website and use it for search. For example, user will be inserted like this:

users.insert({
  name_ref: texts.insert({text: "John Doe", type: USER_NAME}),
  description_ref: texts.insert({text: "This is a test user", type: USER_DESCR}),
});

Is it a good solution, or so many inter-collection dependencies will kill MongoDB, and I need to use some other appproach?

Author:grigoryvp,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/27738336/what-is-a-correct-mongodb-collection-structure-for-full-text-search
yy