Hello, I'm struggling with deleting a document from my MongoDb using an object.
Let me explain:
const removeDocument = function (db, callback) {
// Access the collection of documents
const collection = db.collection(documentName)
// Delete the specified document
console.log(trimNameToDelete)
collection.deleteOne({Video_trim: trimNameToDelete}, function (err, result) {
assert.equal(err, null)
assert.equal(1, result.result.n)
console.log('Document removed')
callback(result)
})
fs.unlink('./public/videos/cut-videos/' + documentName + '/' + trimNameToDelete.trimName + '.mp4', (err) => {
if (err) {
console.log('Failed to delete local image: ' + err)
} else {
console.log('Local image successfully deleted')
}
})
}
Where the value of trimNameToDelete is:
{"trimName":"cut2","startTime":"00:00:05","endTime":"00:00:15"}
and the document in MongoDb looks like this in the shell:
{ "_id" : ObjectId("5abe67897a9b9e0933c64acd"), "Video_trim" : { "trimName" : "cut2", "startTime" : "00:00:05", "endTime" : "00:00:15" } }
The error message I'm receiving is:
AssertionError [ERR_ASSERTION]: 1 == 0
Due to technical limitations, the Id cannot be used for deleting.