从mongoDB检索的对象中的未定值

时间:2018-07-12 12:23:45

标签: javascript mongodb express

我从MongoDB中读取了一个对象,并成功检索了该对象,但是当我尝试单独打印其值时,会打印一些值,并且某些值显示为未定义,我正在共享其模型和代码。

>
                             Model.js
let mongoose = require('mongoose');
let mongoosePaginate = require('mongoose-paginate');
let moment = require('moment');
let service = require('../routes/services');
class Order {
constructor() {
this.init();
this.orderModel = mongoose.model('orders');
}

async getDeliverables(){
  return this.orderModel.find({ $where: "this.total_amount > 
   this.amount_paid" 
 })
}

init() {
var Schema = mongoose.Schema;
var order = new Schema({
  order_number: String,
  order_date: Date,
  patient_id: String,
  patient_name: String,
  payment_summary: [{
    balance_amount: String,
    receipt: String,
    p_date: String,
    p_method: String,
    comment: String,
    p_amount: String
  }]
  });
  order.plugin(mongoosePaginate),
  mongoose.model("orders", order);
 }
}

module.exports = new Order();

以下是Routes.js文件中的代码

 router.get('/getdeliverables', jsonMiddelware, (req, res, err) => {
 let increment = 0;

 const getDeliverables = async () =>{
 let orders = await orderModel.getDeliverables();
 let email = "_id"; // here if i use email it says undefined i use as "email"
 res.send(orders[1][email]);
 }
getDeliverables()
 .then(res.ok)
 .catch(err => console.log(err));

});

其对_id的响应为“ 5b3b8d959760978cc1830fb9” 对于电子邮件,它说未定义

0 个答案:

没有答案