Jump to content

mongodb delete by key value


Recommended Posts

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);



Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...