Execute multiple mongo scripts from the commandline - javascript

For executing a single query script (query.js) from the command line the following code was enough.
mongo db-name < query.js
I would like to execute (or match) multiple query files, such as query1.js, query2.js and so on. I tried the following code with no success.
mongo db-name < query*
Please help me out here.

mongo will not allow you to do it you will get an amibgous redirect error. Do this
cat query* | mongo --nodb
the | takes the output of cat query* passes it as input to mongo which in turn executes any thing it gets. cat does not execute the queries it only outputs the content of the files and passes it to mongo.

Related

Passing only the required rows of data from CSV file to Jmeter based on a criteria

I have a csv file which has the input in the below format (It has no headers as first row):
India,QA,1200,
India,QA1,1201,
India,QA2,1202,
USA,Dev1,5580,
USA,Dev2,5580,
AUS,Dev3,3300,
AUS,Dev4,3301,
I have configured the CSV Data Set Config component and have given the respective path and variable name details. Snapshot below:
from the command line argument, i will be invoking the Jmeter jmeter.bat -t C:\Users\Dev\Desktop\JI\testscript.jmx -JCountry=Indiawhich also has a parameter called JCountry=India.
Now, I have to use this value (India) and then search the csv file's first column and if it matches, I need to send only those particular rows matching to the country name given from the cmd to the script.
I thought of using If Controller but how can I check the csv files first row and when there is a match, send those details to the script.
The easiest option would be dynamically generating a CSV file with only India lines
Add setUp Thread Group to your Test Plan
Add Test Action sampler to the setUp Thread Group (this way you won't have an extra result in .jtl file)
Add JSR223 PreProcessor as a child of the Test Action Sampler
Put the following code into "Script" area:
String country = props.get('Country')
def originalCsvFile = new File('C:/Users/Dev/Desktop/JI/JVMDetails/Details.txt')
def countryCsvFile = new File('C:/Users/Dev/Desktop/JI/JVMDetails/Country.txt')
countryCsvFile.delete()
originalCsvFile.eachLine {line ->
if (line.startsWith(country)) {
countryCsvFile << line
countryCsvFile << System.getProperty('line.separator')
}
}
Configure your CSV Data Set Config to use C:\Users\Dev\Desktop\JI\JVMDetails\Country.txt as this file will have only those lines which start with what you have defined as Country property
More information:
Apache Groovy - Why and How You Should Use It
Groovy Goodness: Working with Files
You need to loop through CSV, see example or other examples.
As the second example use in while condition the variable from CSV: ${Country} .
Inside loop you need to add If Controller with condition to compare country variable against country property:
${__jexl3("${__P{Country}" == "${Country}")}
Checking this and using __jexl3 or __groovy function in Condition is advised for performances

captureing output of nodejs via PHP exec

I am trying to get the output from my node.js script via PHP exec thats wrapped inside an ajax call I am able to call it i think and get some feed back, but console.log doesn't seem to return to the output var
This is how i call the script
$ex = exec('/usr/local/bin/node '.$path.'doAjax.js >/dev/null/ 2>&1 &',$_POST,$out);
var_dump($ex,$out);
In doAjax.js i do
console.log('hhhhhhhhhhhhh');
But all i get for output is
string(0) "" array(0) { }
Is there another way todo output or capture it ?
yes the code and output where switched, but then i always got code 8
i semi solved this problem by moving code to the httpd doc root and changing to shell_exec
though i still need to make sure apache won't be able to display the node code

command line argument in js file for mongodb

I am running a js script to work on mongodb as
mongo localhost:27017/dbname mongodump_isp.js
In the mongodump_isp.js file, I am doing at the very beginning
conn= new Mongo();
db=conn.getDb("dbname");
I have to again provide the database name inside the js file. How can I provide that dynamically?
The conn part is not necessary but you can just set the "database" name like this:
var db = db.getSiblingDB("dbname");
And then all references to db afterwards will use that database, or you can set another variable to another db connection
But if what you are talking about is specifying the db value on the command line, then you do not need any extra lines in your code as the value of db is already set to what you specified.

command line argument to a javascript file that works on mongodb

I have a javascript file ( .js ) that works on MongoDB. I run the .js file as
mongo localhost:27017/dbname myjsfile.js .
How can I send command line arguments while running this JavaScript file ? I want to send database name and collection name as command line argument.
Well, you are already setting the database in use as you connect via:
mongo localhost:27017/dbname
So it is now on database "dbname". That is carried through to the db variable. Which is just a placeholder for the "current" database object.
That means that anything in your "script":
var results = db.collection.find().toArray();
For example is using the database you selected and the collection you named.
Need more? This is valid to:
db["mycollection"].find();
It's just JavaScript to the shell.
if you want a collection to be set as a variable then do something like this:
mongo localhost/mydb --eval "var users = db.users" myfile.js
Or otherwise just do that in you JavaScript file. You can test that by:
mongo localhost/mydb --eval "var users = db.users" --shell
And in the shell you now have a variable users that is "aliased" to the users collection.
cli argument no. But you can read a json file and parse it in your script.
// config.json - {"dbname":"dbname","collection":"mycollection"}
var args = JSON.parse(cat("config.json"));

Can I import data from excel sheet into instruments UIAutomation?

I want to write script for a screen where there are two fields and I just want to test with different possibilities of values for those fields, whether it will navigate to further screen. But combinations of data to enter into these fields is too large. So can I import data from excel/any other file where my data is already stored?
Yes it is possible. You can acquire every data that you are able to acquire in a bash script. Write a script file that prints the desired information to the standard output. For example
#!/bin/bash
cat myfile
You can run this bash-script from UIAutomation and get the output of it with this command
var result = target.host().performTaskWithPathArgumentsTimeout(full_path_to_your_script, [""], 10);
Now your can use the output of your bash script:
element.setValue(result.stdout);
Refer fabe's answer here, https://stackoverflow.com/a/19016573/344798
Refer https://stackoverflow.com/a/20626488/344798

Categories