简体   繁体   中英

Removing array schema element in nodejs

I am removing accepted proposals from my database.So by making ProjectSubmit.pending = true ,I am updating my database.But when I accepted these proposals I added them into a array schema and now i want to remove that index from array.

That's my schema :

 const SupervisorSchema = new Schema({ email: { type: String, unique: true, lowercase: true }, name: String, password: String, username: { type: String, unique: true, lowercase: true }, proposals: [{ type: String }], secretToken: { type: String } }); 

This is my route :

 router.get('/remove-accepted-proposal/:id', (req, res, next) => { ProjectSubmit.findOneAndUpdate( {_id : req.params.id},{pending: true},function(err, supervisor) { if(err){ console.log(err); return res.send(err); }else{ next(); } }); Supervisor.findOneAndRemove({ _id: req.params.proposals }).then((supervisor) => { res.redirect('/supervisor-list'); }); }); 

How can I remove that element?Thanks in advance.

if you say remove from the database do you mean remove from the collection? Can you let me see a sample structure of that object field assuming you already have say 3 different elements. Pls give example and also elaborate what you intend to do. Give a use case example. thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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