I've just discovered Mongoose's Populate Virtuals method, and it's going to save me a ton on my current project. I'm looking to extend it even further, though. Is there an easy way to populate based on multiple local/foreign key pairs? Here's an example of what the code might look like (Note: this is probably not a great example, but hopefully it conveys the basis of my question).
var workerSchema = new Schema({
name: String,
locationCode: String,
departmentCode: String
});
var deparmentSchema = new Schema({
locationCode: String, //Note: neither location nor code
code: String, //are unique, but the combination of them are
manager: String,
otherInfoAboutDepartment: String
});
workerSchema.virtual('department', {
ref: "Department",
localField: ["locationCode", "departmentCode"],
foreignField: ["locationCode", "code"]
});