I am trying to get the user data by setting the track: true
. But the updatedBy
is returned with user id
. I want to push the tracked user data to the element. Inside the user model execution, the element.userDetials
is working but not pushing the data to the element. Outside of the user model consoled as undefined
.
view.on('init', function (next) {
var q = keystone.list('Post').paginate({
page: req.query.page || 1,
perPage: 5,
//maxPages: 10,
// filters: {
// state: 'published',
// },
})
.sort('-publishedDate')
.populate('author categories');
if (locals.data.category) {
q.where('categories').in([locals.data.category]);
}
q.exec(function (err, results) {
locals.data.posts = results;
locals.data.posts.results.forEach(function(element,index){
User.model.findById(element.updatedBy).exec(function(error,user){
element.userDetails = 'Dr. ' + user.name.first + user.name.last;
console.log(element.userDetails);
next(error);
});
});
next(err);
});
});