Notification texts go here Contact Us Buy Now!

.insertOne is not a function

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

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.