Sunday, 4 June 2017

mongo db rest Api returns allways same entry

I am working on the development af a MEAN app and I have a curious problem:

I have created an API which allows me to get one single document by id:

//Get Single Line
router.get('/lines/:id', function(req, res, next){
    db.lines.findOne(
        { _id: mongojs.ObjectId(req.params.id)},
        function(err, line){
        if(err){
            res.send(err);
        }
        res.json(line);
    });
});

Now when I call http://localhost:3000/api/lines/593379eb0cbd3a4efcdc1875 I get what I expect:

{"_id":"593379eb0cbd3a4efcdc1875","name":...

But, when I move this project to a live Server, when I call http://mydomain/api/lines/593379eb0cbd3a4efcdc1875 I allways get the first document in my collection:

{"_id":"59337c480cbd3a4efcdc1876","name":

Even if I try some id that does not exist - I allways get only the first document. I really cant figure out, what the probem here is....



via Stanislav

No comments:

Post a Comment