I am new to node and mongodb, I have created a embedded/nested document, when I am trying to delete it using router.delete method its resulting in the following error: TypeError: Converting circular structure to JSON at JSON.stringify (). How to fix this and delete my document?
I tried with both findByIdAndRemove and findByIdAndDelete of the mongodb method.
**Article Schema**
const articleSchema = new mongoose.Schema({
articleName: {
type: String
},
author: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Author'
}],
comments: [commentSchema]
})
const Article = mongoose.model('Article', articleSchema)
**Route Delete Method**
router.delete('/:id', async (req, res) => {
const article = Article.findByIdAndDelete(req.params.id)
res.send(article)
})
**Comment Schema**
const commentSchema = new mongoose.Schema({
articles: {
type: new mongoose.Schema({
articleName: {
type: String
},
author: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'Author'
}],
})
},
users: {
type: new mongoose.Schema({
name: String
})
},
comment: String
})
**User Schema**
const userSchema = new mongoose.Schema({name: String, email: String})
UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON at JSON.stringify (<anonymous>)