Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error E QUERY [thread1] SyntaxError: invalid property id @(shell) using and/or with find()

I am getting the error while using this query db.a.find({$or:[{"name" : "aekansh"},{"age" : 21}]}).pretty()

as E QUERY [thread1] SyntaxError: invalid property id @(shell):1:11

collection a stores the data as

{ "_id" : 10, "name" : "aekansh" }
{ "_id" : 11, "name" : "ram" }
{ "_id" : ObjectId("59dda15e153802c1d1cf8500"), "name" : "ramu" }
{ "_id" : 12, "nm" : "raj", "age" : 21 }
{ "_id" : ObjectId("59dda1d26b740896d9f067a3"), "nm" : "rj", "age" : 22, "bfff" : "yes" }
{ "_id" : ObjectId("59dda1ea11fc6ddeb8784f7e"), "nm" : "rj1", "age" : 22, "bfff" : "yes" }

I have looked at syntax and I think it is right. Why I am getting the error. Thanx in advance.

Edit- I am using online terminal for MongoDb https://www.jdoodle.com/online-mongodb-terminal

like image 711
Aekansh Kansal Avatar asked Aug 13 '26 11:08

Aekansh Kansal


1 Answers

As was mentioned before your query is correct.

If fails on this online terminal it means terminal is buggy.

You have in fact 3 solutions about which I know:

  1. Install MongoDB on your local computer and use MongoDB Compass or MongoShell to query your database.
  2. Use Mongo Web Shell which is accessible on MongoDB documentation site.
  3. The last option is to set up free cluster from Mongo site. They give you for free some space in cloud, set up database for you and as in first option you can use MongoDB Compass or MongoShell to query it from you local computer.
like image 174
Ziemowit Stolarczyk Avatar answered Aug 15 '26 08:08

Ziemowit Stolarczyk