I am tryin to process the data found from a query. however, but I am not able to get back the results from it for some reason.
I am able to see it found 2 records from the query, but I cant get the actual records. not sure where I am messing up here
const channelQuery = Channel.find({ fields: { $all: channelFieldsFieldNames } })
let fetchedChannels;
channelQuery
.then(documents => {
fetchedChannels = documents;
return Channel.count();
})
.then(count => {
console.log({
message: "Channels fetched successfully!",
channels: fetchedChannels,
maxChannels: count
});
})
.catch(error => {
console.log(error)
res.status(500).json({
message: "Fetching channels failed!"
});
});
this is what i see in the terminal:
{
message: 'Channels fetched successfully!',
channels: [],
maxChannels: 2
}
its weird because I use the same snip of code in other places in my app and it returns the count and the records perfectly, but not this time
so i just want to know how to process the records from the response
i found a few similar stackoverflow posts but they didnt did not discuss how they process the data, they only talked about the query itself How to query MongoDB with "like"