Help! My Collection don't return my expect value


#1

Hi guys, I’m new on meteor and I need your help.

I have this js, where I define my collection and your methods.

import { Meteor } from ‘meteor/meteor’;
import { Mongo } from ‘meteor/mongo’;
import { check } from ‘meteor/check’;

export const Profiles = new Mongo.Collection(‘profiles’);

Meteor.methods({
‘profiles.byNameAndTimes’: function (nameProfile, times) {
check(nameProfile, String);
check(times, Number);

var profiles = Profiles.find({name:nameProfile, times: { $eq: times }});
console.log(profiles.count());
console.log(profiles)
if(profiles.count() === 0){
  throw new Meteor.Error("profiles.byNameAndTimes", "Can't find any Profile for name "+nameProfile+" and times "+times+".");
}

return profiles; 

}
});

And I call this method like this:
import {Profiles} from ‘…/…/api/profiles/profiles.js’;

Meteor.call(‘profiles.byNameAndTimes’, profile, numberOfTimes, function (error, result) {
if(error){
console.log(error);
} else{
console.log(result);
}
});

The problem is. I execute the same query on Command Line and I have the result I expected, but when I call from my client nothing happen, I just receive the Meteor.error because the find method cannot find any data.

I insert values on this collection on main.js inside a server’s folder on Meteor.startup.

Thx for everyone who tries help me.!


#2

@thsrocha are you sure you imported your method so Meteor can know about it. Give this a read: http://www.meteor-tuts.com it explains Methods & Errors quite easily.

Plus, In your method body

return profiles.fetch(); // not just profiles.