Take the example of History: history consists of many sentences; in my case, history will never exceed 20 sentences. It’s better to make a diagram for the Story and another for the Sentences and, finally, make a reference in History to the sentences that make up the story:
var SentenceSchema = new mongoose.Schema({
sentence: {
type: String,
validate: validateSentence,
trim: true
}
});
var StorySchema = new mongoose.Schema({
sentences: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Sentence'
}]
});
Or is it better to place offers directly in the story:
var StorySchema = new mongoose.Schema({
sentences: [{
sentence: {
type: String,
validate: validateSentence,
trim: true
}
}]
});
For a story of 20 sentences (maximum), to get the whole story, for the first case we have to make 20 associations ... Not so efficient ... But the second case is more suitable for expansion, for example, if I want to display only some random sentences or update offer ...
, , . , , MongoDB.
.