qinking126
qinking126

Reputation: 11885

mongoose, how to create a schema has object in it?

here's my photoSchema. it has a dbEntry object. should I create another dbEntry schema and ref it in the photoSchema. Or whatever I have is good enough? I am new to mongodb, try to figure out a correct way to create schema.

    var photoSchema = new mongoose.Schema({
        userId:         ObjectId,
        type:           String,
        createdOn:      {type: Date, default: Date.now},
        isDeleted:      {type: Boolean, default: false},
        isDownloaded:   {type: Boolean, default: false},

        dbFile: String,
        dbEntry: {
            revision:       Number,
            rev:            String,
            thumb_exists:   Boolean,
            bytes:          Number,
            modified:       Date,
            client_mtime:   Date,
            path:           { type: String, unique: true}
        }
    });

Upvotes: 0

Views: 87

Answers (1)

user602525
user602525

Reputation: 3264

It depends on how you plan to access the data. If you want to get the dbEntry object each time you query a photoSchema document, then what you have is probably the way to go.

If however, you're going to use dbEntry independent of the photoSchema document, then you should split it up and just keep a ref to it.

You can always fetch the ref using mongoose "populate"

Upvotes: 1

Related Questions