David Abulashvili
David Abulashvili

Reputation: 124

MongoDB: error code - 10068, invalid operator: $oid

I tried to query in my mongoDB database using java code, but it throws

java.lang.IllegalArgumentException: Cannot parse query: { _id: {$oid:"myId"}}

I run same query in mongoDB shell

> db.collection.find({ _id: {$oid:"myId"}})

but it fails with error

error: { "$err" : "invalid operator: $oid", "code" : 10068 }

What is the reason of this error and how to solve this problem?

Upvotes: 3

Views: 1374

Answers (1)

Graciano
Graciano

Reputation: 518

As the error message says invalid operator $oid

You can query using one of those

db.collection.find({_id: "your_id"});
db.collection.find({_id:ObjectId("5408c3aaca92988d9c70343d")});

Upvotes: 0

Related Questions