Node.js删除查询“mongodb”

我一直在试图理解为什么这个删除查询不能工作几天,我只是不能看到问题。
我已经尝试了许多不同的删除查询,如deleteOne,findOneAndDelete,deleteMany,但都没有工作。
我为node.js使用“mongodb”客户端

mongo.connect(serverAddress, (err, db) => { //(db connection is ok, server can find and create documents) var doc = db.collection('myCollection'), docToDelete = "575807172154b7a019ebf6db"; //I can see the same document id on my database doc.deleteOne({"_id":docToDelete}, (err, results) => { console.log(`Request success : ${results.result.ok}, documents deleted : ${results.result.n}`); //Request success : 1, documents deleted : 0, the document is still on my database }); } //the doc var is the same I use to add/find documents (and it works). 

当我在MongoClient等软件中使用相同的查询时,它可以正常工作。
我已经尝试了许多解决scheme张贴在这个网站上,并抱歉,如果错误太明显,但我完全失去了。
谢谢你的帮助。

问题是数据库中的_idObjectIdtypes,但是在查询中它是一个String 。 你必须严格的,否则查询将不匹配的文件。

尝试这个:

 const mongodb = require('mongodb'); ... doc.deleteOne({ _id : mongodb.ObjectId(docToDelete) }, (err, results) => { ... });