簡體   English   中英

使用 Delphi 連接到 MongoDB Atlas

[英]Connection to MongoDB Atlas with Delphi

我正在使用 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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM