我有几千个字符串(items
)想要翻译。我的 MongoDB 结构如下:
@document = {:item => "hello", :translations => {:fr => {:name => "bonjour",
:note => "easy"}, :es => {:name => "hola", :note => "facil"}}}
:translations 字段可以包含更多语言和属性。我想运行查询,例如检索没有特定语言翻译的所有项目,或检索法语翻译为“bonjour”的所有项目。
我不知道该怎么做。有没有更好的方法来构建我的数据库以实现这些目的?我正在使用node.js。
谢谢。
最佳答案
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?
我相信你的结构是正确的。您必须熟悉 Dot Notation .
关于带有嵌入式文档的 MongoDB 数据库设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8319600/