Say I have a mongoSchema of user with the following field
googleId: String,
name: String,
Language : [{}],
User can initially specify an array of language-set [up to 5] on their profile page.
For example, user can have 2 language set as below:
Language :
[main: {name: English, code: ko}, secondary: [{name:Japanese, code: jp}, {name:Chinese, code: en}]],
[main: {name: Korean, code: ko}, secondary: [{name:Japanese, code: jp}, {name:English, code: en}]
From this information, I want to render out only the post that matches the following preference.
For example post with English to Japanese, English to Chinese (from first language set)
as well as post with Korean to Japanese, Korean to English (from second language set)
My post schema has
postName: String
original: {},
target: {},
For example,
postName: 'Korean to Japanese Post'
original: {name: Korean, code: ko}
target: {name: Japanese, code jp}
What should I put inside the curly brackets to fetch the posts with specified language set
const prefLang = req.user.Language
const post = await Post.find({ some query using prefLang to check over matching original and target })
res.send(translations)
Languagedefined as in your code? becausemain: [Object]would mean array of objects and[Array]would mean array of arrays. (2.) Also, your in your example,secondaryshould have multiple objects right? currently you have a single objects with duplicate keys. (3.) your post schema has original and target, but your did not mention aboutuser.originalanduser.targetso what isreq.user.originalandreq.user.target? Isn't it supposed to beuser.Language?