function DeleteOne cannot directly delete rows in mongoDB
fexli opened this issue · 1 comments
fexli commented
Describe the bug
using the following code (rows are created before delete function)
taskId := task.ID // typeof: *primitive.ObjectID ,sample: ObjectID("62c6ddc7fa2cd2b1c1642c2c"
mgm.Coll(&Task{}).DeleteOne(context.Background(), bson.M{"_id": taskId})
could delete the target row but leaves the data with field _id
left
I check the database through mongodb tool and find that there are many documents with the same ID in the table
search script:
db.task.find({})
.projection({_id:ObjectID("62c6ddc7fa2cd2b1c1642c2c")})
.sort({_id:-1})
.limit(50)
and the result like following ():
Key | Type | Value
(1) 62c6ddc7fa2cd2b1c1642c2c Document
{
_id: ObjectID("62c6ddc7fa2cd2b1c1642c2c")
}
it can't delete the row completely, I'm not sure if this is caused by my operation or understanding mistake.
Expected behavior
Delete the whole document completely (not even _id
field)
Screenshots
Environment (please complete the following information):
- Windows 10 x64
- mongodb.net official database
fexli commented
use find and not to use projection, sorry for my misunderstanding.