Monday, 24 April 2017

How to return multiple Mongodb Collections in one app.get request?

I need to load two sets of data from two different mongodb collections onto one page.
My route page that makes the request through mongoose looks like this

app.get('/testPage', function(req,res){
    dbReadOne.find({}, '', function(error, dataOne){
        res.json(dataOne);
    });
    dbReadTwo.find({},'', function(error, dataTwo){
        res.json(dataTwo);
    });
});

My Angular factories look like this

app.factory('dataOneFactory', function($resource){
    return $resource('testPage/:dataOne', {}, {
        query: { method: 'GET', params:  {symbol: 'dataOne'}, isArray: true}
    })
});
app.factory('dataTwoFactory', function($resource){
    return $resource('testPage/:dataTwo', {}, {
        query: { method: 'GET', params:  {customList: 'dataTwo'}, isArray: true}
    })
});

I'm completely lost on how to do this. I'd appreciate any advice I can get on this issue. Thanks.



via user3731342

No comments:

Post a Comment