Quantcast
Channel: Mongoose model seperations - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by twcardenas for Mongoose model seperations

$
0
0

Yes, you should seperate them. To link them you would just put the profile schema Id as a field on the other models.

const profileSchema = new Schema({
  userId: Schema.Types.ObjectId
})

const experienceSchema = new Schema({
  userId: Schema.Types.ObjectId
})
const educationSchema = new Schema({
  userId: Schema.Types.ObjectId
})

Then you would just query the experience collection by the userId to get their experiences. This is the way I'd recommend.

Another way wouldbe to put experienceIds on the profile schema that would reference the Experience model and could use the populate method to fill the fields.


Viewing all articles
Browse latest Browse all 2

Trending Articles