deleteOne not working

I’m looking at the last lecture in Chapter 2 and none of my delete commands are working. it’s acknowledging the command but not executing it…

here’s my command:{ _id: ObjectId(‘5be654a510007ca4cbb98294’)});

here’s the message I get:
{ “acknowledged” : true, “deletedCount” : 0 }

Double check the way you specified the value for _id. If you don’t see it, google the manual page for deleteOne, or research something like “MongoDB deleteOne objectid”.

I copied the _id directly from Compass, and tried setting it with both single and double quotes. I also compared it character by character with the script in the lesson, and it seems to match exactly, other than the fact that the value for _id was different. Is there something I’m missing?

If the _id values do not match … :thinking:

Start Simple — Double Check you are working in the same db & collection in Compass & shell

  • Use Compass as a Visual Aid and to Verify that the doc exists. { utilize the filter }
  • Use the mongo shell findOne() to search for the same document

If they are the same … then proceed with the deleteOne() action.


Ooh, good idea to try findOne() first.

I did already do all the checks to make sure I was looking at the same database, etc, and filtered in Compass, so that’s a great next step. Thanks!

1 Like

Thanks to your question I was forced to double-check the deleteOne() manual page.

Along the way I learned something new! :smiley: Initially I thought your syntax was off, but it wasn’t :slight_smile: So, thank you for making me check!

1 Like

Wayne, thank you! Doing a find() first worked.

1 Like

@Kirstin_95006 ,

You are Welcome. Glad to have Helped. :sunglasses:
Sometimes you have to step back, take a breath, and start simple.

The funny part is I spent my entire work day doing that :stuck_out_tongue_winking_eye:

(While actually using some of the things I learned in class!)

1 Like

I am having the same problem as Kirstin_95006.
Here is the confirmation
“acknowledged” : true,
“insertedIds” : [
I got after I pushed the documents. Then tried to delete the first item in the list with:{"_id": “ObjectId(‘5c94dfb001349305909b1e86’)”})
but no luck, I got the responce: { “acknowledged” : true, “deletedCount” : 0 }

By the way I even deleted the whole reviews database and added it back. Still no luck. Help please

Try the solution that Wayne offered: insert your records, then find the one you want to delete, then delete it. For some reason that made a difference for me.

I have tried it but no luck. It seems I could not select a document using “_id” selector both on the console and Compass app. I have tried to use “reviewer_id” and it works.
When I use the _id filter with the findOne method it returns null, and same thing on the Compass app too.

This is absolutely not working. I have gone through this video over and over, researched the docs, and I keep getting a ReferenceError every time I run the command shown on the video:

MongoDB Enterprise Sandbox-shard-0:PRIMARY>“5d218c370252d02c42e8f92b”)


“_id” : ObjectId(“5d218c370252d02c42e8f92b”),

“reviewer_id” : 275410481,

“rating” : 2.5,

“reviewer” : “Matthew Samuel”,

“text” : “There have been better movies made about space, and there are elements of the film that are borderline amateur, such as weak dialogue, an uneven tone, and film cliches.”


MongoDB Enterprise Sandbox-shard-0:PRIMARY>{"_id" : ObjectID(“5d218c370252d02c42e8f92b”) } );

2019-07-06T23:26:12.871-0700 E QUERY [js] ReferenceError: ObjectID is not defined :


MongoDB Enterprise Sandbox-shard-0:PRIMARY>{"_id" : ObjectID ( “5d218c370252d02c42e8f92b”) } );

What am I doing wrong?

You need to pass the _id value as an ObjectID, not a string
This may help

Hi @Sarah_39095,

Please check your above query as this should return error.

Following is the correct way to pass _id field in the query filter:{"_id" : ObjectId(“5d2478b166c2bde3db6800f1”)})

Same is the format for deleting documents using _id field.

Also, try to avoid copy/paste the queries as it might sometimes give errors.

Please let me know, if you have any questions.


I was having the same problem, then I figured out that I had mistakenly run use reviews
because the function is it wont find a Database named reviews

then I ran use video, after that both find one and delete one worked.

1 Like

Hi @Soura_90090,

I’m glad your issue got resolved. If you have any query then please feel free to get back to us.

Happy Learning :slight_smile:

Shubham Ranjan
Curriculum Support Engineer

Hi everyone, I found a solution to this, according to an example found on the mongodb doc.

The trick is to actually assign your collection to a variable, then operate on that variable using the standard dot notation.

Mongodb seems to have trouble setting up the refs to different collections within the dbs, this has happen to me on multiple occasions while going through the lessons today.

What I did is this on the mongodb shell:

coll =
coll.deleteOne({_id: ObjectId(“5dc8bc8173b4bb46267612b1”)})
coll.deleteMany({reviewer_id: 759723314})

MongoDB Enterprise Cluster0-shard-0:PRIMARY> coll.find({rating : 5}).count()
MongoDB Enterprise Cluster0-shard-0:PRIMARY> coll.deleteMany({rating:5})
{ “acknowledged” : true, “deletedCount” : 3 }
MongoDB Enterprise Cluster0-shard-0:PRIMARY> coll.find({rating : 5}).count()

Also typos and letter capitalization are very important in MongoDB, it cares about those little details!

Hi @harvey_lin_85455,

Yes, this is one of the ways in which you can work with your database and collection in the mongo shell.

Yes, just like any other modern programming language mongo shell is case sensitive. It is basically a javascript interpreter.

Can you please tell me more about the problem that you were facing while trying to reference different collections in a database ?

Shubham Ranjan
Curriculum Support Engineer