while read -r line
do
number = "ranom id generator"
mongo domains --eval "var isexist=db.domains.findOne({name: '$name'}); if(!isexist){db.domains.insert({_id: '$number',name: '$name'})}"
done < "$FIL.final"
这是我的bash脚本,主要代码段
mongo domains --eval "var isexist=db.domains.findOne({name: '$name'}); if(!isexist){db.domains.insert({_id: '$number',name: '$name'})}"
done < "$FIL.final"
在这里,我正在从大文件中读取每一行并插入db,
但是这里我每次插入代码时都会连接到db,
在我的服务器控制台中,我为每个版本看到了这个
MongoDB shell version: 3.0.2
connecting to: domains
MongoDB shell version: 3.0.2
connecting to: domains
MongoDB shell version: 3.0.2
connecting to: domains
..................
但我想连接到DB并插入记录,这样我就可以节省时间,脚本运行, 怎么这么做?
答案 0 :(得分:0)
修改脚本以在循环中创建一个大的Javascript代码字符串。循环之后,使用您创建的字符串调用private int lastNumber = 0;
@Override
public void start( Stage stage )
{
TabPane tabPane = new TabPane();
Button b = new Button( "add" );
b.setOnAction( new EventHandler<ActionEvent>()
{
@Override
public void handle( ActionEvent event )
{
Tab tab = new Tab( "Tab" + lastNumber );
tabPane.getTabs().add( tab );
lastNumber++;
}
} );
Scene scene = new Scene( new VBox( b, tabPane ), 200, 100 );
stage.setScene( scene );
stage.show();
}
一次。