Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i am new to Shell Scripting, Actually i am writing a shell Script for mongo to find specific document, this Shell Script Except a Argument and use in Find Query, So i had write a simple find query:

mongo poc --eval "printjson(db.users.find().toArray())"

That Working Fine, But now problem is that when i want to find Specific document by Passing Users id That provide null record , So here is my Shell Script:

mongo poc --eval "printjson(db.users.find({"userid":"$1"}).toArray())"

i don't know what is wrong, please help so that i m able to write also for update and remove query.

share|improve this question
    
If you hard code the userid inside the query like: mongo poc --eval "printjson(db.users.find({"userid":"1"}).toArray())" Does it still return NULL value? Does This record (userid=x)exists inside the database? I'm not sure it's a shell script issue. – lese Jun 9 at 8:27
    
i had tried this , but it still return null, and record exists.. – Sunny Dhiman Jun 9 at 8:31
    
please, post also the commands you used to create/populate the poc database, so people can test it via shell script like you – lese Jun 9 at 8:38
    
it is simple mongo database you can test own database and set parameters in find query like- find({"key":"value"}) . – Sunny Dhiman Jun 9 at 8:47
    
well, I may have an older version of mongod than you, but I do : use poc > switched to db poc db.getCollectionNames() > [ ] db.users.find({"userid":"1"}) > this does not return nothing, neither NULL document [ ] – lese Jun 9 at 9:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.