Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Mongoose从数组中删除单个对象_Node.js_Mongodb_Mongoose - Fatal编程技术网

Node.js Mongoose从数组中删除单个对象

Node.js Mongoose从数组中删除单个对象,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我有以下邮件模式: var mail = new mongoose.Schema({ from: {type: String, required: true}, subject: {type: String, required: true}, text: {type: String}, note: {type: String}, createdAt: {type: Date, required: true}, files: [ {

我有以下邮件模式:

var mail = new mongoose.Schema({
    from: {type: String, required: true},
    subject: {type: String, required: true},
    text: {type: String},
    note: {type: String},
    createdAt: {type: Date, required: true},
    files: [
        {
            fileName: {type: String},
            fileSize: {type: Number},
            fileType: {type: String}
        }
    ]
});
mongoose.model('Mail', mail);
我使用以下代码从邮件中删除单个文件,但删除了所有文件:(


我尝试了很多解决方案,请任何人都给我一个解决方案。

很抱歉,这是我的代码中的一个问题

您的Mongoose版本是什么?Mongoose v5.3.2我使用了相同的查询,对我来说,它从“文件”数组中删除了一个文档
  Mail.update({_id: mailId}, {"$pull": {"files": {"fileName": file.fileName}}}).exec(function (err, obj) {
         //do something 
  });