2017-02-13 162 views

回答

0

您可以自己创建它。我已经开发了这种代码是从MySQL数据库中读取数据,并把它在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阅读部分,它和它工作正常。