I have 3 collections of Courses, Units, and CourseUnits, which connects Courses and Units.
Currently if I want to get all the Units a Course has, I’m doing this
const course = Courses.findOne({_id: courseId});
const units = CourseUnits.find({courseId}).map(courseUnit => Units.findOne({_id: courseUnit.unitId}));
But would it be faster if I did this instead?
My thinking here is that it’s less calls to the database. The above would be 2 + number of units
while the below would only be 3. (It’s all local anyway because of MiniMongo so maybe it doesn’t matter)
const course = Courses.findOne({_id: courseId});
const unitIds = CourseUnits.find({courseId}).map(courseUnit => courseUnit.unitId);
const units = Units.find({_id: {$in: unitIds}});
Also, how can I run performance tests on things like this in the future? Is there a good guide for that because I would like to be able to do it myself, but I don’t know how