mongodb / laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
https://www.mongodb.com/docs/drivers/php/laravel-mongodb/
MIT License
7.01k stars 1.43k forks source link

Fetching data via tinker #2697

Open ivankrister opened 10 months ago

ivankrister commented 10 months ago

Description:

Steps to reproduce

  1. Install mongo db version 4.1.0 in laravel 10.37.3
  2. Set up using DB_DSN
  3. Fetch any data using model in tinker

Expected behaviour

Display the collection on the specific model that call

Actual behaviour

Error MongoDB\Driver\Exception\InvalidArgumentException Failed to parse URI options: Failed to look up SRV record "_mongodb._tcp.XXXX.XXX.mongodb.net": A temporary error occurred on an authoritative name server. Try again later.

BUT everything fine when calling in routes

alcaeus commented 10 months ago

Hi @ivankrister, does the error persist or does it eventually go away? By default, MongoDB Atlas uses the mongodb+srv protocol in its connection string, which instructs the driver to do a DNS lookup on the given hostname to get the initial list of servers to connect to. The error you're encountering is an error reported by your operating system. Did you confirm that the same connection string was used in tinker and the web application where it works?

ivankrister commented 10 months ago

Yes, @alcaeus i confirm that im using same connection in my web and tinker im using mongodb+srv protocol in my connection and i call config('database.connections.mongodb') in my tinker and web it gives similar result, but error still exists in tinker when fetching data

lokesh-zersys commented 7 months ago

For me its the other way around, From tinker It works, but calling from routes it throws the below error.

No suitable servers found (serverSelectionTryOnce set): [connection error calling hello on 'xxxxx.docdb.amazonaws.com:27017'] {"userId":11,"exception":"[object] (MongoDB\Driver\Exception\ConnectionTimeoutException(code: 13053): No suitable servers found (serverSelectionTryOnce set): [connection error calling hello on 'xxxxx.docdb.amazonaws.com:27017'] at /home/forge/default/vendor/mongodb/mongodb/src/functions.php:520)

@ivankrister is the issue fixed?

alcaeus commented 7 months ago

@lokesh-zersys the error you are receiving is likely unrelated and has a very different root cause.

I've also noted that you're using DocumentDB, so please contact AWS support for any issues you encounter as it's not supported by the MongoDB driver. Thanks.