Reputation: 316
I am writing an app with angular as front end and meteor as back end and I want to retrieve every user in the collection "Users" (added module accounts-ui and accounts-password). But when I execute the following code, it only returns one object (the last added) while there are 3 users.
if(Meteor.isClient){
angular.module('timeAppApp')
.controller('SignInCtrl', function($scope, $meteor, $location) {
$scope.LogIn = function() {
console.log($meteor.collection(Meteor.users).subscribe('users_by_email', $scope.username));
console.log($meteor.collection(Meteor.users).subscribe('all_users'));
};
});
}
if (Meteor.isServer) {
// Returns all users find by email
Meteor.publish('users_by_email', function(emailE){
return Meteor.users.find({'emails.address': emailE});
});
Meteor.publish('all_users', function(){
return Meteor.users.find({}, {fields: {emails: 1}});
})
I'm new to meteor so I'm still experimenting but now I'm really stuck.
Upvotes: 0
Views: 113
Reputation: 2582
Try this, On server side
Meteor.methods({
get_users_by_email: function (emailE) {
return Meteor.users.find({ emails: { $elemMatch: { address: emailE } } }).fetch();
}
});
On client side
$meteor.call('get_users_by_email', $scope.username).then(
function(data){
console.log('success get_users_by_email', data);
},
function(err){
console.log('failed', err);
}
);
Upvotes: 3