function create(user, callback) {
const bcrypt = require(‘bcrypt’);
const MongoClient = require(‘mongodb’).MongoClient;
const url = ‘mongodb+srv://:’+configuration.MANGO_PASSWORD+‘@.mongodb.net/?retryWrites=true&w=majority’;
MongoClient.connect(url, function(err, client) {
if (err) return callback(err);
const db = client.db('db-name');
const users = db.collection('user');
users.findOne({ email: user.email }, function(err, withSameMail) {
if (err || withSameMail) {
client.close();
return callback(err || new Error('User already exists'));
}
bcrypt.hash(user.password, 10, function(err, hash) {
if (err) {
client.close();
return callback(err);
}
user.password = hash;
users.insertOne(user, function(err) {
client.close();
if (err) return callback(err);
callback(null);
});
});
});
});
}
this’s the code for creating user. Could you please help me how to fix this issue