I am writing a node.js webapp using mongodb/mongoosejs. I have a user and a car model and want to keep history of the car. I know there is no right or wrong way to do these things but I am wondering what is the better options.
Option 1: New model that holds the Car and User with dateto and datefrom
const usercarsSchema = new mongoose.Schema({
car : {
type : mongoose.Schema.Types.ObjectId,
ref : 'Car'
},
user : {
type : mongoose.Schema.Types.ObjectId,
ref : 'User'
},
datefrom : Date,
dateto : Date
}
Option 2: Nested History Within The Car Model
const carSchema = new mongoose.Schema({
owner : [{
user : {
type : mongoose.Schema.Types.ObjectId,
ref : 'User'
},
datefrom : Date,
dateto : Date
}]
}
I'm pretty new to mongodb and in the past using MYSQL this would have been three tables. But with Mongodb I can see a nested way of doing it. Which option is the better way of doing this?
question from:
https://stackoverflow.com/questions/65866152/mongoosejs-mongodb-nested-data-vs-new-model 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…