Trying to create a new entry in the DB, but I keep getting an error about my code not being in a fiber. I have no idea what the problem could be. I must add that I am doing the insert on the server side. This is not a Method call from a client.
Here is my code.
import {Meteor} from 'meteor/meteor';
import {Mongo} from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
export const Trxs = new Mongo.Collection('trx');
export const addTrx = (trxn, userId) => {
var date = new Date(trxn.date).valueOf();
var userId = userId;
var catID = trxn.category_id;
var amt = trxn.amount;
var trx_name = trxn.name;
console.log(trxn);
Trxs.insert({
date,
userId,
catID,
amt,
trx_name
});
}
And this is the error I am getting.
Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
Meteor.bindEnvironment
should do the trick – JankapunktbindEnvironment
. – Jankapunkt