Hi,
I would like to seek help on how to publish an array fields based on user profile.
Here’s the user profile:
"profile" : {
"name" : "username",
"company" : "qckPxDw5tc8zyMKMJ",
"branch" : "yeTtBM955A7fbKpDt",
"products" : [
"LY7TCoMJYQ3wa8nJx",
"miGEn6oMNFkFj59qm"
]
},
here’s my publish function:
Meteor.publish( "products", function ( limit ) {
var user = Meteor.users.findOne( {
"_id": this.userId
}, {
fields: {
profile: 1
}
} );
var profile = user.profile.products;
var admin = Roles.userHasRole( this.userId, 'admin' );
if ( admin ) {
return Products.find();
} else if ( limit ) {
console.log( 'User Products:', profile );
return Products.find( profile[ 0 ] );
} else {
return Products.find( profile[ 0 ], {
limit: limit
} );
}
} );
the above publication is working but only for index 0.
What I want is to publish all the products inside users profile.
I’ve tried this approach but I have a cursor error
return Products.find( profile );
i get this error:
Error: Mongo selector can\'t be an array.
What is the best approach on this matter?