I'm trying to find all rows where post_id is the same as I'm searching for. But every time I do the result is empty, and I've double check all values and I should get some result.
This is the method I'm using:
db.collection('posts', function(err, collection) {
collection.find({}, {}, {limit:100}).toArray(function(err, posts) {
if (err) res.send({'error':1,'message':'error getting all posts'});
console.log('Number of posts: ' + posts.length);
posts.forEach(function(entry) {
db.collection('love', function(err, collection) {
collection.find({}, function(err, love) {
if (err) console.log(err);
if (!love) console.log("empty");
if (love) {
console.log(love);
entry.love = love;
}
});
});
});
res.send(JSON.stringify(posts));
});
});
It always enter the third if like if I have a result but in the console I always get [] from the result. Any idea of that I'm doing wrong?
EDIT1: Code updated.