Reputation: 63
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?
Upvotes: 3
Views: 3627
Reputation: 298
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.
Upvotes: 1