Closed RezaErfani67 closed 4 years ago
Do you have any error? What's the final output?
it should add a record on database... but no thing happen... output is: 1 2 3
I'm thinking about your connection. Spawning a new thread requires a new connection to MongoDB. Have you tried adding the connection to the job?
const res = await job(async () => {
global.config=require('./config.js')
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
mongoose.connect(config.database.url , { useNewUrlParser: true });
let i = 0;
console.log(1);
let User = require('./model/user');
console.log(2);
let newuser=new User({nickName:"salam"});
console.log(3);
await newuser.save();
console.log(4); //------------------------------ NOT SHOW---------------------------------------------
return i;
});
yes....thanks a lot