I'm the beginner of nodejs and MongoDB.I tried to design RESTAPI but there was a problem.
Here is my router code.
app.post('/fcm',function(req,res){
var beaconid = req.body.beacon_id;
var my_token_id = req.body.user_id;
User.find({beacon_id: beaconid}, function(err, output){
if(err) return res.status(500).json({error: err});
if(!output) return res.status(404).json({error: 'user not found in User collections.'});
console.log("output user id :"+output.user_id + " beacon: " +output.beacon_id );
target_token_id = output.user_id;
res.json(output);
});
});
And this is user schema.
var userSchema = new Schema({
user_id: String,
beacon_id: String
});
The result of above function in the console is: output user id: undefined , beacon: undefined.
But json from res function is printed properly.
This codes look like very simple but I don't know what is the problem. Please somebody help me.