使用列映射将Excel工作表导入Mongodb数据库

时间:2017-02-13 11:01:05

标签: php import import-from-excel pipedrive-api

使用Column Mapping将Excel工作表导入Mongodb数据库。我需要一个类似于pipedrive导入数据的PHP插件,请提示是否有。

1 个答案:

答案 0 :(得分:0)

您可以自己创建。我开发了这种从Mysql DB读取数据并将其放入mongodb的代码,其代码为:

$collection = $db->createCollection("emp_details");
$collection->createIndex(array('email' => 1));

$getAllEmp = "select first_name, last_name, position, email, office, start_date, age, salary from datatables_demo";
$resAllEmp = mysqli_query($conn, $getAllEmp);

$data   = array();
$count  = 1;
if(mysqli_num_rows($resAllEmp) > 0)
{
    while($row = mysqli_fetch_assoc($resAllEmp))
    {
        $data['_id']        = new MongoId();
        $data['emp_id']     = $count; 
        $data['first_name'] = $row['first_name'];
        $data['last_name']  = $row['last_name'];
        $data['position']   = $row['position'];
        $data['email']      = $row['email'];
        $data['office']     = $row['office'];
        $data['start_date'] = $row['start_date'];
        $data['age']        = $row['age'];
        $data['salary']     = $row['salary'];
        $data['project']    = array('Project1', 'Project2', 'Project3');
        $data['password']   = md5('12345');

        if($collection->insert($data))
        {
            $count++;
        }
    }
}

使用上面的代码并通过删除Mysql部分并添加csv读取部分来修改它,它可以正常工作。