Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

Below is my schema.

**Payment.js**
var PaymentSchema = new Schema({   
    customer: {
       customerRef: {
            type: Schema.ObjectId,
            ref: 'Customer'
        },
        custMemberId : String,
        branch : String
       },
        paymentStatus : String,
        payBalance : Number,
        deliveryMode : String
});

**Order.js**
var OrderSchema = new Schema({
  OrderId : string,
  products :[{type : String}],
  totalCost : Number
});

**Customer.js**
var Customer= new Schema({
Name : String,
previousOrders :[{
      type: Schema.ObjectId,
            ref: 'Order']}

});

I have noted down some of the fields in the schema files. My problem is from a payment page,

If I refer to the previous orders of customer, I am not able to access the array previousOrders.

I try

console.log($scope.payment.customer.customerRef.previousOrders);

the output is 'undefined'

PaymentAPI - service

exports.payment = function(req, res, next, id) {
    Payment
        .findOne({
            _id: id
        })
        .populate('customer.customerRef')
        .exec(function(err, payment{
            if (err) return next(err);
            if (!payment) return next(new Error('Failed to load payment' + id));
                       req.payment = payment;

            next();
        });
};

Please let me know , the other possibilities.

share|improve this question
    
Is this Mongoose stuff at the server end? – zsong Jun 14 '14 at 4:21
    
Yes, this is at server end. The schemas are already designed and I cant change the structure. I am trying for the ways to access this nested object array. – sabari Jun 14 '14 at 4:22
    
can u post ur node service as well... probably you miss something when you retrieving your schema... – Poyraz Yilmaz Jun 14 '14 at 5:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.