问题描述:

I want to loop through an array of objects named tier1.

what I get is this:

TypeError: Cannot read property 'length' of undefined

My code looks something like this:

module.exports.getTier1= function(curUser, callback){

for (var i = 0; i < curUser.tier1.length; i++) {

var val = curUser.tier1[i];

console.log("index: " + i + " val: " + val);

}

};

var UserSchema = mongoose.Schema({

username: {

type: String,

index:true

},

password: {

type: String

},

email: {

type: String

},

name: {

type: String

},

tier1: [Tier1]

});

相关阅读:
Top