edit
As of mongoose documentation, try using
Account.create({ ...params ... }, function (err, small) {
if (err) return handleError(err);
// saved!
})
A Mongoose model doesn't have an insertOne
method. Use the create
method instead:
Account.create({email: req.body.email, password: req.body.password}, function (err, doc) {
The Mongoose docs show how to create documents:
Either via Account.create()
:
Account.create({email: req.body.email, password: req.body.password}, function (err, res) {
// ...
})
Or by instantiating and save()
ing the account:
new Account({email: req.body.email, password: req.body.password}).save(function (err, res) {
// ...
})
insertOne
command is not available in mongoose directly as mentioned in Mongoose Documentation. If you want to use insertOne
command then you need to use bulk command in order to send this command to MongoDB server. Something like below. I hope this works.
Account.bulkWrite([
{
insertOne: {
document: {email: req.body.email, password: req.body.password}
}
}
}]
Use create()
instead of insertOne()
.
https://masteringjs.io/tutorials/mongoose/using-insertone-in-mongoose