Add the following publish


#1

Hi i want to Add the following publications in /imports/api/models/server/publications.js :
brands - must return separate field list " brand" of the list " models"
models - must return distinct fields list “model” and " VehicleTypeId " of the " models" list by taking "brand " parameter


#2

And what is the problem?


#3

I want to know how I can realize the task !


#4

Have you tried following the guide?


#5

Yes, but I 'm new to meteor and I can do a simple publish.


#6

You haven’t really told us enough about the document structure or use-case.

However, I’ll take a leap in the dark and assume that you have a collection of vehicles called models. Each document in that collection contains fields for model, brand and vehicleId (probably with others).

I’ll further assume that your app’s user is going to select a brand from a list of brands (pulled from the collection) and then show a list of vehicles which match that brand.

The first point to make is that if you are holding this “key” information in a single collection, you should use MongoDB’s aggregation pipeline. This lets you do things like find distinct model (although there is also a distinct method for this). It is not reactive by default in Meteor (there is a package for this), but that should not matter for this use case, because:

Point 2: You should probably use Meteor.call/method instead of pub/sub. The overhead of reactivity is really not necessary here (if my assumptions are correct).

Check out the meteorhacks:aggregate package for an easy way to start with aggregations in Meteor.