Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I am saving data into a MongoDB. The data will be saved into 3 Mongoose models that are hierarchical. A User model contains an Activity model array. An Activity model contains an array of Data models. Are the following model definitions correct (or does an explicit reference to the parent model need to be declared)?

I will add any additional details if need be.

User

var userSchema = new mongoose.Schema({
    googleId: {type: String, unique: true, required: true},
    name: {type: String, required: true},
    data: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Activity' }]
});

module.exports = mongoose.model('User', userSchema);

Activity

module.exports = mongoose.model('Activity', {

    name: String,
    data: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Data' }]
});

Data

module.exports = mongoose.model('Data', {

    date: String,
    time: {type: Number, default: 0},
    timestamp: {type: Number, default: 0}
});
share|improve this question

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.