Tuesday, 14 March 2017

Mongoose.js - TypeError: Model.deleteOne is not a function

I am new to node.js, hence a very trivial question.

I have the following lines of code:

(A) Defined a model

var mongoose = require('mongoose');
var genreSchema = mongoose.Schema({
  name:{
    type: String,
    required: true
  }
});

Perform model delete operation

module.exports.deleteGenre = function (id, callback) {
  console.log("Deleting genre: "+ id);
  var condition = {"_id": id};
  Genre.deleteOne(condition, callback);
};

I have referred to the following link on the function.

However, when I run it, it throws the following error:

TypeError: Genre.deleteOne is not a function

If I replace the deleteOne() function with remove(), the code works. Please advise, where am I going wrong.



via Ritwik

No comments:

Post a Comment