简体   繁体   English

如何从 mongodb 数据库和 nodejs 的数组中删除元素

[英]How can I remove element from an array from mongodb database and nodejs

Writing this query in ROBO 3T the code is running properly But in nodejs the code is not working.ROBO 3T中编写此查询代码运行正常但在 nodejs 中代码不起作用。 //schema model //模式model

const mongoose = require('mongoose');

const imageSchema = mongoose.Schema({
    image: [{
        type: String
    }],
    date: {
        type: Date,
        default: Date.now
    }

});

const Image = module.exports = mongoose.model('Image', imageSchema);

//this code run properly //这段代码正常运行

db.images.updateOne(
{_id:ObjectId("5eeb3273977faa1f7419620e")},
{ $pull: { image: "image-1592472179452.png"} }
)

    //this code not run

Image.updateOne({ _id: "5eeb3273977faa1f7419620e" },{$pull:{image: "image-1592472179482.png"}});

Change your export:更改您的导出:

module.exports = mongoose.model('Image', imageSchema);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM