2017-09-05 115 views
0

我正在使用laravel-mongodbhttps://github.com/jenssegers/laravel-mongodb)來操縱mongodb數據。如何用laravel-mongodb創建一個新的MongoDB集合?

如何使用laravel-mongodb創建新的MongoDB集合?

例如:

public function test() 
{ 
    $newArtciels = DB::connection('mongodb')->collection('articles')->where('status', '1')->get(); 

    //I want to ceate a new collection `new_artciels`, and save `$newArtciels` into `new_artciels`,how to write next? 
} 

問:
我想ceate一個新的集合new_artciels,並保存到$newArtcielsnew_artciels,我該怎麼辦?

回答

0

型號

<?php 

namespace App; 
use Jenssegers\Mongodb\Eloquent\Model as Eloquent; 

class new_artciels extends Eloquent 
{ 
    protected $collection = 'new_artciels';} 

控制器

use App\new_artciels; 

這應該爲你工作。