So, I have a fields variable which is correctly initialized. My goal is to use it inside a Fiber. Here is the code :
console.log(fields); //<--- Here it's OK
Fiber(function () {
var qry = Connections.findOne({login:fields[1]});
if (typeof(qry) === 'undefined') {
console.log('INSERT');
console.log(fields); //<--- Here, the variable "fields" is empty
Connections.insert({
login: fields[1],
ip: fields[2],
created_at: Date.now(),
updated_at: Date.now(),
});
} else {
console.log("UPDATE");
}
}).run();
How can I pass the content of the variable fields into the Fiber?
Thanks in advance.
This one should work:
var fields = /* whatever */;
Fiber(function (fields) {
// ...
}).run(fields);
If you want to read more about this look here.
Not sure what fiber is, but try passing your variable as argument of the function:
console.log(fields); //<--- Here it's OK
Fiber(function (fields) {
var qry = Connections.findOne({login:fields[1]});
if (typeof(qry) === 'undefined') {
console.log('INSERT');
console.log(fields); //<--- Here, the variable "fields" is empty
Connections.insert({
login: fields[1],
ip: fields[2],
created_at: Date.now(),
updated_at: Date.now(),
});
} else {
console.log("UPDATE");
}
}).run();