Here is my server side code
Meteor.methods({
addSupportRequest: function (support) {
Support.insert(support, function (err, id) {
if (err)
Dsyko's answer was somewhat on the right track. However, the asynchronous callback will never pass its result to the scope of the original function, which has ended.
What you want is to run the Support.insert
operation synchronously, i.e. having the current fiber yield while I/O is happening. This is what the Meteor._wrapAsync function is for. Luckily for you, there is no need to do this manually because if you just take out the callback from the insert operation, it will run synchronously:
Meteor.methods({
addSupportRequest: function (support) {
var id = Support.insert(support);
// An error may be thrown here, but it certainly won't be a network error because the request will have already reached the server.
console.log("Support request added: " + id);
return id;
});
}