2

Right now i'm thinking of doing it like this:

Board:

const BoardSchema = new Schema({
    title: {
        type: String,
        required: true,
    },
    admins: [
        {
            type: ObjectId,
            ref: 'User',
            required: true,
        }
    ],
    members: [
        {
            type: ObjectId,
            ref: 'User',
            required: true,
        }
    ],
}, {
    timestamps: true,
});

List:

const listSchema = new mongoose.Schema({
    name: {
        type: String,
        required: true
    },
    order: {
        type: Number,
        required: true,
    },
    boardId: {
        type: ObjectId,
        required: true,
        ref: 'Board',
    },
});

Card:

const cardSchema = new Schema({
    text: {
        type: String,
        required: true,
    },
    members: {
        type: ObjectId,
        ref: 'User',
        required: true,
    },
    listId: {
        type: ObjectId,
        ref: 'User',
        required: true,
    },
    boardId: {
        type: ObjectId,
        ref: 'Board',
        required: true,
    },
    order: {
        type: Number,
        required: true,
    },
});

I'm new to mongoDB/noSQL and a database noob in general, and structuring a database seems to not be a very strict science, as everyone seems to do it differently. From what i've seen the rule of thumb is to keep as much data in one collection as possible, basically the opposite of traditional databases, but not always? So should i instead save everything in the Board collection?

Going forward with this project i want to try to replicate how one would do in a real scenario to learn as much as possible. And i've been googling around to try and find the schema structure for the real trello app but i cannot find it. All i know is that they do use mongoDB and they have a separate Collection for Cards because with the amount of data they handle it wouldn't work otherwise. So i assume they have a separate Collection for Lists (and Boards) aswell.

So my question is if these Schemas would work? And what would be the best way to go about getting all the data (when a user clicks on a board) using the boardId and combining it into a List of Cards?

0 Answers0