router.get('/renew/:id',ensureAuthenticated , function(req, res){
// console.log();
Store.findById(req.params.id, function(err, stores){
// console.log(stores);
Plan.find({}, function(err, plans){
Transaction.findOne({"app":req.body.appID},{"sort":{"startDate":-1}},function(err, transOne){
console.log("transOne :" +transOne);
Transaction.find({"_id":transOne._id},function(err, transactions){
console.log("trans :"+transactions);
res.render('edit_store', {
title:'Edit Store',
stores:stores,
user:login.userLogin,
plans:plans,
transactions:transactions
});
});
});
});
});
});
Why is my transOne Variable undefined?
TransOne Undefined
.
So, my transaction variable is errors.
I want to select the most recent document that has appID I choose.
And I want to know how to get the result of findOne.
I used:
transOne = Transaction.findOne({"app":req.body.appID},{"sort":{"startDate":-1}});
But, it return "[Object Object]".
You have written get request then how you will get body in this request it's not a good way to send the body in the get request.
Here
Transaction.findOne({"app":req.body.appID})
You are trying with req.body.appID try to send it in params and perform a find operation.
Thanks, I hope it helps