2011-11-30 75 views
0

我有几千个字符串(items),我想要翻译。我已经构建了我的MongoDB,如下所示:带嵌入式文档的MongoDB数据库设计

@document = {:item => "hello", :translations => {:fr => {:name => "bonjour", 
:note => "easy"}, :es => {:name => "hola", :note => "facil"}}} 

:translations字段可以包含更多的语言和属性。我想运行查询,例如检索所有没有特定语言翻译的项目,或者检索所有具有“bonjour”作为法语翻译的项目。

我不明白我该怎么做。有没有更好的方法来构建我的数据库用于这些目的?我正在使用node.js.

谢谢。

回答

2

我想运行查询,如检索,没有翻译特定语言的所有项目,

.find({ 'translations.fr': {$exists:false} }) 

...或检索所有具有'bonjour'作为法语翻译的项目。

.find({ 'translations.fr.name': "bonjour" }) 

是否有更好的方法来组织我的数据库为这些目的?

我相信你有正确的结构。你将不得不熟悉Dot Notation

0

我会说为了您的目的,模型是好的。你需要mongo dot notation,你可以使用$exists寻找fr和点符号的卓悦 -

find({ "fr.name" : "bonjour" })