Hey Guys need a bit of help with query, the following is the model and i am referencing it to another Model Called Project
const User= new mongoose.Schema({
featured_projects: {
type: [
{
type: Schema.Types.ObjectId,
ref: 'Project'
}
],
}
}, {
timestamps: true,
});
//output below
{
"featured_projects" : ["5bd54c7d65194f200d1c6e2d","5bd41b953fc9f040b08995df"]
}
The Project model is stored as
{
"en": {
"isActive": true,
"amneties": [],
"carasouel_images": [],
"location": "location (en)",
"name": "name (en)"
},
"th": {
"isActive": true,
"amneties": [],
"carasouel_images": [],
"location": "location (th)",
"name": "name (th)"
},
"_id": "5bd54c7d65194f200d1c6e2d",
"createdAt": "2018-10-28T05:43:25.982Z",
"updatedAt": "2018-10-28T05:43:25.982Z",
"__v": 0
},
I am trying to just fetch the "en" from the query
this.find(options)
.populate({
path: 'featured_projects',
populate:'en'
})
.sort({ createdAt: - 1 })
.skip(perPage * (page - 1))
.limit(perPage)
.exec();
But is not working , any help is much appreciated, or any suggestion is much appreciated.
However if i directly try to fetch from the project the "en" field i do this and is working
this.find(options)
.select({ [lang]: 1 })
.sort({ createdAt: -1 })
.skip(perPage * (page - 1))
.limit(perPage)
.exec();
Thank you in advance ! :)