我在MySQL中有一个名为new_ndnc
的表,它包含五个字段。每个字段包含1000万行。将数组插入到MongoDB中
我已经将每个字段读入一个数组,现在我想将整个数组插入到MongoDB中的字段中。
我的代码如下。
#!/usr/bin/perl
use MongoDB;
use MongoDB::OID;
use DBI;
$dbs = 'amrit';
$user = 'root';
$pass = 'walkover';
$dbh = DBI->connect("DBI:mysql:database=$dbs", $user, $pass)
or die "Cannot connect to MySQL server\n";
$conn = MongoDB::Connection->new(
host => 'localhost',
port => 27017,
db_name => 'amrit'
);
$db = $conn->get_database('amrit');
$users = $db->get_collection('hell2');
$abcuid = $dbh->prepare('select Service_Area_Code from new_ndnc');
$abcuid->execute;
@uid;
while (my @row = $abcuid->fetchrow_array()) {
push(@uid, @row);
}
$hh = $dbh->prepare('select phonenumbers from new_ndnc');
$hh->execute;
@route1;
while (my @row = $hh->fetchrow_array()) {
push(@route1, @row);
}
$r4 = $dbh->prepare('select Preferences from new_ndnc');
$r4->execute;
@route4;
while (my @row = $r4->fetchrow_array()) {
push(@route4, @row);
}
$exr4 = $dbh->prepare('select Opstype from new_ndnc');
$exr4->execute;
@exroute4;
while (my @row = $exr4->fetchrow_array()) {
push(@exroute4, @row);
}
$r5 = $dbh->prepare('select PhoneType from new_ndnc');
$r5->execute;
@route5;
while (my @row = $r5->fetchrow_array()) {
push(@route5, @row);
}
$users->insert({
'UserID' => "[@uid]",
'route1' => "[@route1]",
'route4' => "[@route4]",
'route4_extra_bal' => "[@exroute4]",
'route5' => "[@route5]"
}
);
请在你编写的每一个* Perl程序开始时,总是*使用strict和'use warnings',特别是如果你需要帮助的话。 – Borodin
@ user2916639我使用#perl -w – user2916639
运行代码在命令行中''warnings''优于'-w',因为它在词汇范围内,并且可以打开或关闭各个警告类别。 “严格使用”比启用警告更重要。 – Borodin