• Post Reply Bookmark Topic Watch Topic
  • New Topic

db.collection find with query is not working  RSS feed

 
rajesh naga
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

db.collection.find( ) with  query is not working
> db.My_First_Collection.find()
{ "_id" : ObjectId("5860a2d2487cb401d97af151"), "UserName" : "America", "Password" : "Trump", "UserId" : 1, "CreationDate" : "Mon Dec 26 2016 10:25:46 GMT+0530(India Standard Time)" }
{ "_id" : ObjectId("5860a2d2487cb401d97af152"), "UserName" : "NewArk", "Password" : "Obama", "UserId" : 2, "CreationDate" : "Mon Dec 26 2016 10:25:46 GMT+0530 (India Standard Time)" }

> db.My_First_Collection.find( { query: { "UserName" : "NewArk" } } )

> db.My_First_Collection.find(  query: { "UserName" : "NewArk" }  )
2016-12-26T10:34:58.033+0530 E QUERY    [thread1] SyntaxError: missing ) after argument list @(shell):1:35

What is wrong with syntax?


Thanks
 
Mel Reams
Greenhorn
Posts: 13
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rajesh,

I think what you need to do is remove the "{ query: }" part. That is, your command should look like "db.My_First_Collection.find( { "UserName" : "NewArk" } )" (without the quotes)

The way I found that, so you don't have to wait days for somebody to answer next time, is first I googled "db.collection.find" that brought me to https://docs.mongodb.com/v3.2/reference/method/db.collection.find/, and on that page I scrolled down until I found a clear example. If you search for "Find Documents that Match Query Criteria" on that page you'll find a nice simple example of a query with criteria that shows what the command should look like.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!