Reputation: 1455
I have a few thousand strings (items
) that I would like to translate. I have structured my MongoDB as follows:
@document = {:item => "hello", :translations => {:fr => {:name => "bonjour",
:note => "easy"}, :es => {:name => "hola", :note => "facil"}}}
The :translations field can contain many more languages and properties. I would like to run queries such as retrieving all items with no translations for a specific language, or retrieving all items having 'bonjour' as a French translation.
I don't see how I can do this. Is there a better way to structure my database for these purposes? I am using node.js.
Thanks.
Upvotes: 1
Views: 364
Reputation: 45287
I would like to run queries such as retrieving all items with no translations for a specific language,
.find({ 'translations.fr': {$exists:false} })
...or retrieving all items having 'bonjour' as a French translation.
.find({ 'translations.fr.name': "bonjour" })
Is there a better way to structure my database for these purposes?
I believe that you have the correct structure. You will have to become familiar with the Dot Notation.
Upvotes: 3
Reputation: 4001
I'd say that for your purpose the model is good. You need mongo dot notation, you can use $exists
to look for fr
and dot notation for bonjour -
find({ "fr.name" : "bonjour" })
Upvotes: 1