Ad
Check The Result Of FindOne Mongodb Nodejs
mongo.connect(url, {useNewUrlParser: true}, function(error, db) {
if (error) throw error;
var dbo = db.db("mydb");
console.log("connected to databse successfully");
dbo.collection("users").findOne({}, {"email": email}) (function(err, result) {
if (!result) {
res.sendfile(__dirname + '/register.html');
} else {
dbo.collection("users").insertOne(data, function(err, collection){
if (err) throw err;
console.log("Record inserted successfully");
console.log(collection);
res.status(200).send('You are loged in, Welcome!');
});
}
});
});
I want to check the result. If the mail is already in the db I don't add it in the record. But it doesn't work
Ad
Answer
Your findOne
query is incorrect
.
dbo.collection("users").findOne({}, {"email": email}) (function(err, result){
Should Be
dbo.collection("users").findOne({"email": email}) (function(err, result) {
Ad
source: stackoverflow.com
Related Questions
- → Maximum call stack exceeded when instantiating class inside of a module
- → Browserify api: how to pass advanced option to script
- → Node.js Passing object from server.js to external modules?
- → gulp-rename makes copies, but does not replace
- → requiring RX.js in node.js
- → Remove an ObjectId from an array of objectId
- → Can not connect to Redis
- → React: How to publish page on server using React-starter-kit
- → Express - better pattern for passing data between middleware functions
- → Can't get plotly + node.js to stream data coming through POST requests
- → IsGenerator implementation
- → Async/Await not waiting
- → (Socket.io on nodejs) Updating div with mysql data stops without showing error
Ad