In MongoDB, is it better to demarcate Schemas or put them together?

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({

  // Some other fields ...

  sentence: {
      type: String,
      validate: validateSentence,
      trim: true
  }

  // Some other fields ...

});    

var StorySchema = new mongoose.Schema({

  // Some other fields ...

  //Sentences of the Story
  sentences: [{
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Sentence'
  }]

  // Some other fields ...

});

Or is it better to place offers directly in the story:

var StorySchema = new mongoose.Schema({

  // Some other fields ...

  //Sentences of the Story
  sentences: [{

    // Some other fields ...

    sentence: {
        type: String,
        validate: validateSentence,
        trim: true
    }

    // Some other fields ...

  }]

  // Some other fields ...

});

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.

.

+4
3

? ? , , , , .

. (), . , .

+2

imho, bson, .

, ACID .

+2

, max 20 MongoDB "" ""

, "" .

-1

Source: https://habr.com/ru/post/1648518/


All Articles