0

I know that if the size of the document grows, it will have a bad influence on Mongolia. So I avoid the following embedding document method.

However, many of the bulletin board basic examples use the following code.

var boardSchema = mongoose.Schema({
writer: String,
password: String,
title: String,
contents: String,
comments: [{
    name: String,
    memo: String,
    date: {type: Date, default: Date.now}
}],
count: {type:Number, default: 0},
date: {type: Date, default: Date.now},
updated: [{contents: String, date:{type: Date, default: Date.now}}],
deleted: {type: Boolean, default: false}
});

In the case of bulletin boards and comments, is it possible to simply implement the embedded document method? Or did I misunderstand?

In addition, I implemented bulletin boards and comments in the following way.

var boardSchema = mongoose.Schema({
...
comments: [{type: ObjectId}],
...
});

var commentSchema = mongoose.Schema({
    name: String, 
    memo: String,
    date: Date
});

When creating in the comment schema, I implemented it by pushing the objectId as the bulletin board schema.

HungryBird
  • 85
  • 1
  • 5
  • *"bad influence on Mongolia..."* I had no idea that there was actually this amount of influence on world affairs. Honestly, Embedding vs Referenced is really a matter of opinion, and it's really more about how your application uses the data more than any "right way" to do things. The topic has been covered before. See [MongoDB relationships: embed or reference?](https://stackoverflow.com/q/5373198/2313887) and [Mongoose populate vs object nesting](https://stackoverflow.com/questions/24096546/mongoose-populate-vs-object-nesting) – Neil Lunn Nov 04 '17 at 06:11
  • Thank you so much! – HungryBird Nov 04 '17 at 06:55

0 Answers0