I want to retrieve Documents from a Collection where the value of one field equates to a specific value (specifically, where the Document field “wjllu_workerid” equals the passed-in arg “workerid”), but I only want one field actually returned, expressly “wjllu_jobloc”).
The commented-out attempts to do this fail; the other one compiles, but does not give me the needed “jobloc” value:
Does anybody have an example of how to do this (restrict the document count of a result set based on a failter, but also restrict the “width” of each Document by restricting the fields returned)?
First you should return a cursor inside Meteor.publish, so you souldn’t apply fetch(), just find(). (See the docs for find and fetch).
Second, Meteor mongo query looks like find({<selector>}, {fields: {<fields restriction>}, skip: <skip docs count>, limit: <limit docs count>}). For example I wanna publish posts list by author id, and pass only 3 records with title field only:
The logic behind this is that I only want Documents for the selected worker, where the Document was created by the current user, and the only field I want to be returned from the Documents that meet those two criteria is “jobloc”.