Populating nested documents

I’m a newbie in mongodb and I’m trying to create a kanban task management, so when the user logs in he can fetch all its boards and populate it each board with its corresponding data. Here are my schemas :
´´´

const BoardSchema = Schema({
	userId: {
		type: Schema.Types.ObjectId,
		ref: 'User',
		required: true,
	},
	boardName: {
		type: String,
		required: [true, 'Board name is required.'],
	},
	columns: [
		{
			type: Schema.Types.ObjectId,
			ref: 'Column',
			required: true,
		},
	],
})

const ColumnSchema = Schema({
	columnName: {
		type: String,
		required: [true, 'Column name is required.'],
	},
	tasks: [
		{
			type: Schema.Types.ObjectId,
			ref: 'Task',
		},
	],
	board: {
		type: Schema.Types.ObjectId,
		ref: 'Board',
		required: true,
	},
});
const TaskSchema = Schema({
	title: {
		type: String,
		required: true,
	},
	description: {
		type: String,
		required: true,
	},
	status: {
		type: String,
		required: true,
	},
	subtasks: [
		{
			type: Schema.Types.ObjectId,
			ref: 'Subtask',
		},
	],
	column: {
		type: Schema.Types.ObjectId,
		ref: 'Column',
		required: true,
	},
});
const SubtaskSchema = Schema({
	title: {
		type: String,
		required: [true, 'Subtask title is required.'],
	},
	isCompleted: {
		type: Boolean,
		required: true,
		default: false,
	},
	task: {
		type: Schema.Types.ObjectId,
		ref: 'Task',
		required: true,
	},
});

´´´
And this is what I’m trying to execute but it brings me an empty array of columns: //! Get boards by user
´´´

const getUserBoards = async (req = request, res = response) => {
	const userId = req.user._id;
	try {
		const userBoards = await Board.find({ userId }).populate({
			path: 'columns',
			populate: {
				path: 'tasks',
				populate: {
					path: 'subtasks',
				},
			},
		});
		res.json({
			ok: true,
			userBoards,
		});
	} catch (error) {
		res.json({
			ok: false,
			msg: `Some error happened: ${error}`,
		});
	}
};

´´´

I’m doing it this way to handle easily the CRUD operations for each schema, but if anybody has a better idea to handle this please provide me some information.

Hello @Jaaciel_Briseno_Espinoza, Welcome to the MongoDB community forum,

The simple principle of the document database is “Data that is accessed together should be stored together”.

Try to normalize your schemas and reduce them to one or two collections, and avoid populating/joining to another collection and it will improve the query.

You can refer to the MongoDB available resources for schema design,

Developer Center: MongoDB Developer Center
Free University Courses: MongoDB Courses and Trainings | MongoDB University

Thanks for taking the time to answer! I used to have just one schema (the board schema) but i was getting getting some problems for example updating a single property of the board. (e.g. toggling the isCompleted property of the subtasks) so that’s why I split my schemas to perform CRUD operations in specific properties .