0
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]".

Hardik Shah
  • 3,241
  • 2
  • 17
  • 36
Sun
  • 105
  • 2
  • 9

1 Answers1

1

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

REF: HTTP GET with request body

  • If another question has an answer that also answers this question then please consider flagging this question as a duplicate (which you will be able to do when you've earned 15 reputation points). – ChrisF Jul 19 '18 at 11:03