Given a MongoDB srv connection string, how can I make a connection with mongoc?

3 ビュー (過去 30 日間)
Brian
Brian 2023 年 8 月 29 日
コメント済み: Lasse 2024 年 2 月 28 日
The mongodb drivers for most APIs are initialized using a connection string - which, in the SRV protocol, looks something like "mongodb+srv://<username>:<password>@example.example.mongodb.net/?retryWrites=true&w=majority". However, the initialization with the database toolbox's mongoc instead asks for server and port info. I've tried to decompose my connection string into parameters for mongoc in the following manner:
conn = mongoc("example.example.mongodb.net",27017,"DbName",UserName="...",Password="...");
But get the following error:
Error using database.mongo.connection
[Mongo Driver Error]: No suitable servers found (`serverSelectionTryOnce` set): [Failed to resolve
'example.example.mongodb.net'].
I've also tried variants, like "example.example", and appending "mongodb+srv://" to the start, which raises a [Mongo Driver Error]: Invalid host string in URI.

採用された回答

Brian
Brian 2023 年 8 月 30 日
After reaching out to support, the solution is conn = mongoc(connectionString,databaseName)
Even though this isn't stated anywhere in the documentation, as of 2023b.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by