MongoDB对象未通过删除。猫鼬

Nit*_*hin 0 mongoose mongodb node.js

我正在尝试删除MongoDB文档,但没有被删除

我的架构是

const mongoose = require("mongoose");

const InvestorSchema = mongoose.Schema({
    name: {
        type: String,
        index: true,
        required: true
    },
    logoUrl: {
        type: String,
        required: true
    },
    website: {
        type: String,
        index: true,
        unique: true,
        required: true
    }
});

module.exports = mongoose.model("Investor", InvestorSchema);
Run Code Online (Sandbox Code Playgroud)

并且我尝试使用这些文件,但没有一个文件删除了该文件。此外,我还在localhost没有用户和角色的情况下运行。

// Required models
const InvestorModel = require("mongoose").model("Investor");

const deletedInvestor = InvestorModel.remove({ _id });
const deletedInvestor = InvestorModel.deleteOne({ _id });
const deletedInvestor = InvestorModel.findByIdAndRemove(_id);
const deletedInvestor = InvestorModel.findOneAndRemove({_id});
const deletedInvestor = InvestorModel.findByIdAndDelete(_id);
const deletedInvestor = InvestorModel.findOneAndDelete({_id});
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

小智 5

  try {
   InvestorModel.deleteOne( { "_id" : ObjectId("563237a41a4d68582c2509da") } );
    } catch (e) {
   console.log(e);
    }
Run Code Online (Sandbox Code Playgroud)