var employeesEdited = [];
var employees = Employees.find({group: 'ABC', task : { $in: ['CHANNEL MANAGER','SUPERVISOR','LINE LEADER'] }}
, {employeeNo: 1, firstName: 1, middleName: 1, lastName: 1, task: 1, supEmpNo: 1, supName: 1});
console.log(employees.count()); // I get 0 on this
employees.forEach((employee) => {
console.log('inside for each'); // this does not run, no logs in browser
employeesEdited.push(employee.employeeNo, employee.supEmpNo, 'test_tooltip');
});
employees.forEach((employee) => {
console.log(`Emp no: ${employee.employeeNo}`);
});
console.log(employeesEdited);
What I am trying to do is to loop through the returned cursor of my collection using for each. But it doesn’t appear to execute. The console.log inside the forEach loop does not execute.
Also the Cursor.count() method returns 0.
BUT when I console.log the returned cursor from the find function, I can see that there are items in that object if I console.log(employees)
Not really sure what I am doing wrong here, I followed the syntax as per documentation in meteor.
Also I changed the code from using function() to using the fat arrow but still the same results
This code is inside the Template.template.onRendered event. Other codes run, but this forEach is not working for me.
I tried to access the the details in the Cursor via dot notation but for some reason when I reach the _map, I am not able to get the contents.
I think in your query you’ve missed the field specifier and you’ve just gone and started which fields to include. You’re supposed to have {fields: {...}}
It just sounds like you’re not correctly subscribed (or if you are - the subscription isn’t providing any data which matches your query). Remembering that the client will only be able to query data that it has been “given” by the server.
I have been trying to understand more what you said: the client will only be able to query data that it has been “given" and played with the app.
I have two publications, one that gets all the employees, and another that gets only the employees of a certain group.
what happens is that when I first load the page that gets all the employees, and then switching to my page for a specific list of employees to be loaded to the org chart, it works.
but if I go straight to the org chart without first visiting the employee all list, it doesn’t work.
not sure why is that, my two publications are mostly the same besides the filter for the group.
Ah so you’re subscribing to the same collection twice in the same application?
That is a funny area I am not 100% sure on the behaviour.
I would be asking whether or not you need this data to be re-active or not…
If not - you are probably better off getting it via a method call.
It is less work on the server and much easier to debug because it behaves more like an API call.