Laravel-mongodb: Please help

Created on 3 Feb 2017  路  3Comments  路  Source: jenssegers/laravel-mongodb

I am using your project laravel-mongodb. It is very helpful for me.
However, I have some problem when using laravel-mongodb.

  1. How I create a collection with custom field when insert -> like:
    {
    '_id' : AUTO_INCREMENT
    'username' : unique (phuocduy1988)
    'view_count' : interger 64 bit ()
    'average' : double
    }
  2. How to make index for username

  3. Please give me more example how to using:
    $client = DB::getMongoClient();
    $db = DB::getMongoDB();

  4. I cannot using DB in laravel Controller
    $client = DB::collection('spot')->where('name', 'John')->get();
    I got an error:
    Call to undefined method Illuminate\Database\MySqlConnection::collection();

Please help me!

question

Most helpful comment

I found the Solution for this error.
You have to use this

$db = \DB::connection('mongodb')->getMongoClient();

and mongodb is the name that you use in the config/database.php

All 3 comments

I have the same issue.

I found the Solution for this error.
You have to use this

$db = \DB::connection('mongodb')->getMongoClient();

and mongodb is the name that you use in the config/database.php

Thank Wu4m4n,
I found other solution.
I custom other class to connect direct to mongodb via php driver mongodb/mongodb.

Was this page helpful?
0 / 5 - 0 ratings