Help with matching collections


Hey guys, I have a (hopefully quick) question for you guys about something I may be just approaching incorrectly. This may be more of a programming questions than a Meteor specific one, but in my case it applies to Meteor so here I am. Anyway…

I have a ‘Reports’ collection that has very similar fields as my ‘Equipment’ collections. I am generating a single report by gathering information about how the user would like to sort/view items in the ‘Equipment’ form. On the server I am then grabbing all of the fields that the user filled out in the Report (reports.find().fetch().fieldName). This will give me some fields with a value and some ‘undefined’. I am then using these variables to run ‘find()’ through the Equipment to return all items that match the form they filled out but it doesn’t return what I want because of the ‘undefined’. I am sure this is confusing, so here is an example of what I am talking about…

    (field name="Company")
    (field name="Employee")
    //inserted into Report

//assuming the user wanted to sort by company

company = Reports.find().fetch().Company;
employee = Reports.find().fetch().Employee;

Equipment.find({ Company: company, Employee: employee });

Since the user selected a company but left Employee blank, I want to sort through Equipment for all items matching that company, however I think it is returning all items where Equipment has a Company and no Employee (when I want to return w/ and w/o Employee).

Hopefully this all makes sense. I can clarify if it doesn’t.

Thanks for the help in advance.


I am currently thinking that if I have an object for the Reports

[{ _id: 'asdasdbh', Company: 1 }]

that I should just delete the property _id and then insert my object into my Equipment.find()

But I am not entirely sure how I would accomplish that.


solved the issue. Rather simple when I found the delete command.

This was what I did

//delete the fields not related to equipment

const info = Reports.find().fetch()
delete info[0]._id;
return Equipment.find(info[0])