javascript - Using Meteor methods to pass user array -
i have meteor method on server:
returnusers: function(){ console.log(meteor.users.find()); } and following call on client:
'click #share_button': function(ev){ ev.preventdefault(); meteor.call('returnusers'); } but returns empty array:
localcollection.cursor {collection: localcollection, sorter: null, _selectorid: undefined, matcher: minimongo.matcher, skip: undefined…}
how return array of users?
you need fetch documents in order return array method. this:
returnusers: function() { var selector = {}; var options = {fields: {username: 1}}; return meteor.users.find(selector, options).fetch(); } note it's critical filter fields in order avoid sending of users' secrets client. more information see "published secrets" section in common mistakes article.
it's hard without knowing use case, instead of using method, may make more sense publish subset of users client, rather fetching of them on event.
in order result server, should invoke method this:
meteor.call('returnusers', function(err, users) { console.log(users); });
Comments
Post a Comment