#1 2019-03-04 08:49:49

Radiesel
Member
Registered: 2019-03-04
Posts: 2

MongoDB Atlas connecting to database / collection

Hi together,
I started using the mORMot framework because it support authentication using SCRAM-SHA-1. So far I setup a MongoDB Atlas cloud system through www.mongodb.com. I did setup a user in the "admin" database having also readwrite access to another database (lets call this "testdb"). So far I successfully was able to connect to the cloud database and even was able to authenticate the user against the admin database by using the follwing code:

var
  Client: TMongoClient;
  DB: TMongoDatabase;
  Coll: TMongoCollection;
  
  Client := TMongoClient.Create('shard0',27017,true,'shard1,shard2','27017,27017'); // connection string the cloud system gave me
  DB := Client.OpenAuth('admin','user','password');

This so far works and it seems user is successfully connected. But I am trying to access another database 'testdb' (which user has access to - some client-apps work w/o problems) by using this code:

  DB := Client.Open('testdb');
  Coll := DB.Collection['testcoll'];

Allthough "testdb" and "testcoll" exists on the server and user has access to it (client-apps are working and I already created some records), the last call isn't working.

So I am actually stuck, because I don't know what I am doing wrong here.

Any help would be appreciated. Best regards

Offline

#2 2019-03-05 10:05:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: MongoDB Atlas connecting to database / collection

Perhaps there is some problem with the shards definition.

To to connect only to the main/master server.

Offline

#3 2019-03-05 10:17:29

Radiesel
Member
Registered: 2019-03-04
Posts: 2

Re: MongoDB Atlas connecting to database / collection

thanks for your reply. First I thought, other client-apps are working, so it can't be a problem with the shards. But I figured out, that there are two secondary shards and one primary shard. When connecting to the primary shard, it's working! I can select a different collection and also retrieve data from it.

This helps a lot. Thank you very much!

Offline

Board footer

Powered by FluxBB