xshockz
-
Posts
2 -
Joined
-
Last visited
Content Type
Profiles
Forums
Downloads
Posts posted by xshockz
-
-
If you're not using mongoosejs (which automatically casts the string into ObjectId) then you'd have to cast the string into an ObjectId.
const idToDelete = '5dcc20c3770b9707143301fb' // if not using mongoose collection.deleteOne({_id: new mongodb.ObjectID(idToDelete)}, callback}; // if using mongoose > 4 (deleteOne isn't supported on mongoose 4 or higher) collection.findByIdAndRemove({_id: idToDelete}, callback);
references:
https://docs.mongodb.com/manual/reference/method/db.collection.deleteOne/
https://mongoosejs.com/docs/api.html#model_Model.findByIdAndRemove

mongodb delete by key value
in Scripting
Posted
The (1) and (2) are probably just the index of the array. You can't use that.