This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Hi,
I'm very new to Mongo and coming from a mySQL background so please excuse any ignorance on best practice and all that.
I am trying to query my collection of jobs and send back paginated results based on searchText and location.
Within the object being returned I also need to summarise the locations column and contractType column. I need these to be as close to the below as possible but I can't work out how to actually get a sub-query of the locations and contract types of the jobs found before the limit was applied.
Any help is hugely appreciated.
Cheers Leigh
PostJob.find(
{
'descriptions': { $regex: searchText, $options: 'i' },
'location': { $regex: location, $options: 'i' }
}
)
.sort({'updatedAt': -1})
.skip(page)
.limit(limit)
.then(postjobs => {
jobData.docs = postjobs;
jobData.limit = limit;
jobData.page = page;
jobData.contractTypeTotals = {
temp: 100,
permanent: 50
};
jobData.locations = [
{city: London, total: 20},
{city: Manchester, total: 20},
{city: Glasgow, total: 110}
];
return res.status(200).json(jobData);
})
.catch(next);
Post Details
- Posted
- 7 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/mongodb/com...