I'm currently using MeteorJS in conjunction with MongoDB.
Within my project, I am managing two collections:
- events, which contains idEvent
- eventsType, which contains idEventType (a finite list of event types)
The relationship between the two collections is established by matching idEvent == idEventType
.
The objective is to create an array of events, each associated with its corresponding event type object.
Although the following code works, I personally find it quite messy... What are your thoughts on this?
events() {
// Retrieve event types
const eventsType = EventsType.find();
const eventsTypeArray = [];
eventsType.forEach((ev) => {
eventsTypeArray[ev.idEventType] = ev;
});
// Retrieve events
const eventsList = Events.find();
const eventsListArray = [];
// Merge data from both collections
eventsList.forEach((ev) => {
const evObj = ev;
evObj.type = eventsTypeArray[ev.idEvent];
eventsListArray.push(evObj);
});
return eventsListArray;
}
Thank you! :D