3

I m getting started with MongoDb scripting. My requirement is to query the mongodb for a process status and based on it kick start another process, in shell script. I ve written the following js to query and return the value from mongodb :

var statusValue=db.Collections.find({"Name":"UV"},{Status:1,_id:0}).sort({Sequence:-1}).limit(1).map( function(u) { return u.Status; } );

print (statusValue);

I call this js from a shell script. Is there a way to return the value of 'statusValue' to the calling shell?

1 Answer 1

1

Use "--eval" option to get return value. For example: return=`mongo localhost/test --quiet --eval 'db.version()'` Replace "db.version()" with your own expression. Refer to the offical document.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.