Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

My '/messages' API is used to query mongodb for document with given 'hostname' and 'day'. When I test it with 'postman' I got correct response, array of objects. But when angular client used, it gives me empty array [], why?

Controller

apiSvc.post('/messages', {hostname: "XYZ", day: '1'})
            .then(function (response) {             
                console.log(response.data);
            });

SERVICE

.factory("apiSvc", function($http) {
        return {
            post: function(url,data) {
                return $http.post(url,data);                                  
            },            
        }
    })

ROUTER

router.post('/messages', function (req, res, next) {
    console.log(req.body.hostname, req.body.day);
    Message.find({day: req.body.day, hostname: req.body.hostname},
        function(err, message) {                          
            res.send(message);
    });

});
share|improve this question
    
Looking on server side I have this: 'VAL-VSX-02 1 string string []' for Angular service and this for Postman: 'WAL-VSX-02 1 string string [{..}]' which is array of objects. So same request, different response.. – irom Dec 11 '15 at 19:46
    
Once again, looking at array length: VAL-VSX-02 1 string string 0 <<<<<<<<<<<<<<<<<<<<<<<<<<<Angular service WAL-VSX-02 1 string string 42 <<<<<<<<<<<<<<<<<<<<<<<<<<<Postman – irom Dec 11 '15 at 19:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.