使用Delphi连接到MongoDB Atlas



我正在将Delphi Seattle与Firedac一起使用,我需要连接到MongoDB Atlas上的基础。

在Firedac上,我只能选择放置服务器的ip,但Atlas只提供连接字符串。

如何使用Firedac+Delphi连接MongoDB Atlas?

PS:我试图获得连接字符串中引用服务器地址的部分;mongodb+srv://address.address.mongodb.net/myFirstDatabase";,但是delphi无法解析这个地址

我也无法工作,而是使用REST API。例如

RESTClient1.BaseURL := 'https://data.mongodb-api.com';
RESTRequest1.Client := RESTClient1;
RESTRequest1.Resource := '/app/data-cemfo/endpoint/data/v1/action/findOne';
RESTRequest1.Method := rmPOST;
RESTRequest1.AddAuthParameter('api-key', 'FHZ....your API key', 
pkHTTPHEADER, [poDoNotEncode]);
RESTRequest1.AddParameter('Content-Type', 'application/json', pkHTTPHEADER);
RESTRequest1.AddParameter('Access-Control-Request-Headers', '*', 
pkHTTPHEADER);
body := TJSONObject.Create;
body.AddPair ('collection', 'mycollection');
body.AddPair ('database', 'mydbs');
body.AddPair ('dataSource', mydsrc');
subObj := TJSONObject.Create;
subObj.AddPair ('numInventory', 10);
body.AddPair ('filter', subObj);
RESTRequest1.AddBody(body);
RESTRequest1.Execute;
jsonStr := RESTResponse1.JSONValue.ToString;

最新更新