Я нашел решение!Спасибо.
Новый код: // получать все сообщения от друзей из db
app.get("/api_posts_by_friend/:id", function(req,res){
db.open( function(err,mongoclient){
mongoclient.collection('users', function(err,collection){
collection.find(objectId(req.params.id)).toArray(function(err,results){
if (err){
res.json(err);
} else {
mongoclient.close();
var friends = results;
console.log("results="+results[0]._idFollowing);
db.open( function(err,mongoclient){
mongoclient.collection('postagem', function(err,collection){
collection.find({_idUser: {$in: friends[0]._idFollowing}}).toArray(function(err,results){
if (err){
res.json(err);
} else {
res.json(results);
}
mongoclient.close();
});
});
});
}
});
});
})
;}