Hi I am trying to save the userId as soon as the user signs up in a separate collection using Meteor.userId() and methods (using mdg:validated-method). But everytime I get an error which says that User Id must be of type String.
When I tried giving a random string value it passed the schema validation. Is this because Meteor.userId() returns a value that is not of String type?
Hi,
on default the userId is a string when the user is logged in or null, if he isn’t.
Just log your userId with console.log(typeof Meteor.userId()) before you pass it to your Collection and check which type do you get.
But the default of the meteors’ account user Collection is String for ids and I am not sure but I think you can’t really set it to ObjectId … ? So if your User is logged in, Meteor.userId() should be a String.
The problem has been solved. Meteor.userId() returns a string. The parameter of the Meteor method call is of type Object. The error was that, I was trying to insert that object into the collection instead of the string value which was expected and being validated. Found out after using console.log(typeof usersId). Thanks!