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}
});