2014년 12월 27일 토요일

Re: multilingual fields in mongodb

On Friday, July 2, 2010 1:21:17 AM UTC+9, лойк wrote:
Or you can simply do that

{
   name: {
        en: 'length',
        fr: 'longueur',
   }
   unit: 'mm'
}

You can still index over name and you only have one instace...I would explain more but my powersupply just died...and I only have few minutes of battery....I'm so screwed.

I tried this method in my mongo collection, and tried to add a text index. Using your example, I'd do a db.collection.ensureIndex({ name: 'text' }) but when doing a find() using $text: { $search: "something" }, I didn't get any results. Does the text index really work for subdocuments? 



For a relatively small and fixed set of words, like the field names in your collection, I wouldn't store the translations in the database. I would keep a translation table for each supported language and use it to translate the field names for display.


댓글 없음:

댓글 쓰기