.insertone Is Not A Function
I want to preface this by saying I have read several posts here regarding this issue. I have a node/express/mongo app with the following: app.js: var express = require('expre
Solution 1:
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) {
Solution 2:
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:
newAccount({email: req.body.email, password: req.body.password}).save(function (err, res) {
// ...
})
Solution 3:
edit
as of mongoose documentation, try using
Account.create({ ...params ... }, function (err, small) {
if (err) return handleError(err);
// saved!
})
Solution 4:
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}
}
}
}]
Post a Comment for ".insertone Is Not A Function"