[英]How to Get Data using Mongoose when Multilingual is stored in collections
I have saved data in mongo db like我已经在 mongo db 中保存了数据,例如
{
"title": {
"ar": "arabic name",
"en": "english name"
},
"description": {
"ar": "ar-description",
"en": "arabic description"
},
"subCategories": [{
"title": {
"ar": "arabic name",
"en": "english name"
}],
}
Expected OutPut :预期 OutPut :
{
"title": "arabic name",
"description": "arabic description",
"subCategories": [{"title": "arabic name"}],
}
How can i query to mongoose to give this result on basis of language(en,ar).我如何查询 mongoose 以根据语言(en,ar)给出此结果。 i am using mongoose, nodejs and express.
我正在使用 mongoose、nodejs 和 express。 if cant with mongoose then any other solution?
如果不能使用 mongoose 那么还有其他解决方案吗? Thank you:)
谢谢:)
Best way to do would be storing an unwinded
document最好的方法是存储
unwinded
的文档
{
"title": {
"ar": "arabic name",
"en": "english name"
},
"description": {
"ar": "ar-description",
"en": "arabic description"
},
"subCategories": [{
"title": {
"ar": "arabic name",
"en": "english name"
}],
}
will become会变成
// ar doc
{
"lang": "ar",
"title": "Arabic name",
"description": "ar-description",
"subCategories": [{
"title": "arabic name"
}],
}
// en doc
{
"lang": "en",
"title": "English name",
"description": "en-description",
"subCategories": [{
"title": "english name"
}],
}
In order to find an ar doc为了找到一个ar doc
Model.find({lang:'ar'})
would give you the expected result.会给你预期的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.