[英]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. 我正在从数据库中删除接受的建议。因此通过使ProjectSubmit.pending = true,我正在更新数据库。但是当我接受这些建议时,我将它们添加到了数组模式中,现在我想从数组中删除该索引。
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.
假设您已经说了3个不同的元素,您能否让我看到该对象字段的示例结构。 Pls give example and also elaborate what you intend to do.
请举个例子,并详细说明您打算做什么。 Give a use case example.
给出一个用例示例。 thanks
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.