-
Description:Steps to reproduce
Expected behaviourReturn documents from mongo collection Actual behaviourReturn null or empty array I have followed the instruction listed here my dsn is mongodb://127.0.0.1:27017 (I have even tried localhost instead of ip) In either case when using
and php tinker code is
Not sure what I am missing. Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
Hello, looking at the thinker commands you sent, it seems that you did not save the model object. Call |
Beta Was this translation helpful? Give feedback.
-
I am having the same issue after updating to 5.2. When I run the query in raw, it works but when I run it via eloquent nope no result, empty. I thought connection then came up with to do it raw which works but eloquent doenst $raw = \DB::connection('mongodbPart')->getMongoClient() |
Beta Was this translation helpful? Give feedback.
-
Yo try this. manually add a function to get the table to your model and make it return just the name of the collection see if htat fixes it for you. The issue was NOT in mongo but other small tweaks that came with a composer update. I suspect 11.44 to 11.44.2 or something. anyway try and see :) |
Beta Was this translation helpful? Give feedback.
-
I spotted the issue. We deprecated usage of class RVDB extends Model
{
use Searchable;
protected $connection = 'mongodb';
- protected $collection = 'annotation';
+ protected $table = 'annotation';
protected $primaryKey = 'accession';
protected $keyType = 'string';
} |
Beta Was this translation helpful? Give feedback.
-
Thank you, I can confirm, all three solutions worked. Using raw statement works: for mongodb/laravel-mongodb v5.2 statement was I also tested overwritting getTable function in my Model And finally replaced protected property collection with table @GromNaN suggested. This one worked as well. Thank you everyone, marking it closed. |
Beta Was this translation helpful? Give feedback.
Thank you, I can confirm, all three solutions worked.
Using raw statement works: for mongodb/laravel-mongodb v5.2 statement was
$raw = \DB::connection('mongodb')->getClient() ->selectCollection('DB_NAME', 'TABLE_NAME') ->find([], ['limit' => 10]) ->toArray();
I also tested overwritting getTable function in my Model
function getTable() { return $this->collection(); }
And finally replaced protected property collection with table @GromNaN suggested. This one worked as well.
Thank you everyone, marking it closed.