[英]Failed to connect to local azure cosmosdb emulator
我在我的 Win10 計算機上安裝了Azure CosmosDB 模擬器,並且可以看到啟動頁面:
但是當我嘗試通過 Robo3T 或命令行連接到數據庫時,它不起作用。 我使用以下 cmd :
mongo mongodb://localhost:foofoojf5%2FR%2Bob0N8A7Cgv30VRDJIWEHLM%2B4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw%2FJw%3D%3D@localhost:10255/admin?ssl=true
我遇到了以下問題:
2019-07-18T14:33:27.265+0200 W NETWORK [thread1] 5000ms 毫秒后無法連接到 127.0.0.1:10255,放棄。 2019-07-18T14:33:27.266+0200 E QUERY [thread1] 錯誤:無法連接到服務器 localhost:10255,連接嘗試失敗:connect@src/mongo/shell/mongo.js:237:13 @(connect ):1:6 異常:連接失敗
它是本地的,所以我認為沒有端口問題。 是否可能與本地證書或我的公司防火牆有關?
我用 ROBO3T 工具連接了 mongo 模擬器,請看我的配置。
首先,從此鏈接獲取模擬器連接字符串。
mongodb://localhost:C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==@localhost:10255/admin?ssl=true
然后創建連接配置:
聯系:
認證:
SSL:
點擊測試按鈕:
用戶界面:
就我而言,要為 MongoDb 交互 Azure CosmosDb API,我們需要在 %localappdata%\\CosmosDbEmulator 下創建一個專用的新文件夾並啟用 MongoDb 端點 v3.6(請參閱下面步驟 1中的 PowerShell 命令)。
注意:無論出於何種原因,如果 CosmosDb 模擬器重置為默認文件夾路徑 %localappdata%\\CosmosDbEmulator(或)無法在 Robo 3T 中連接,則始終在步驟 1 中再次執行以下 PowerShell 腳本。
注意:從 Robo 3T v1.4 開始,我們在連接設置對話框中沒有 SSL 選項卡。 相反,我們有一個選項卡 TLS。
1. Download and install Azure CosmosDb Emulator from https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator?tabs=powershell%2Cssl-netstd21
2. Download and install Robo 3T (1.4.2 or latest) from https://robomongo.org/download
3. To show Azure CosmosDb emulator related database(s) in Robo 3T client app
Step 1
- Launch Azure CosmosDb Emulator
(Optional: Just to check CosmosDbEmulator is started successfully)
- Open Powershell as administrator and execute below commands
# PowerShell Script
# Change directory to default location where CosmosDb emulator is installed.
cd\
cd '.\Program Files\Azure Cosmos DB Emulator\'
# [Optional] If any cosmosDb emulator instance is running then shutdown
.\Microsoft.Azure.Cosmos.Emulator.exe /shutdown
# To interact Azure CosmosDb API for MongoDb, create a new folder "<MongoDb>" under
# %localappdata%\CosmosDbEmulator and enable MongoDb endpoint v3.6
.\Microsoft.Azure.Cosmos.Emulator.exe /DataPath="$env:localappdata\CosmosDBEmulator\MongoDb" /EnableMongoDbEndpoint=3.6
Step 2
- Now CosmosDb emulator will be successfully started,
and launches the URL https://localhost:8081/_explorer/index.html in the browser
- Note down MongoDb connection string details from browser which will be required
while creating new Robo 3T connection. The default MongoDb connection string format is
mongodb://username:password@host:port/[database]?ssl=true
- Username: localhost
- Password (Primary Key): C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
- Port: 10255
- Database: admin
Step 3
- Launch Robo 3T
- Click on Create new connection
- In "Connection" tab
- Provide Name of the connection as "<CosmosDbEmulator>"
- Add port number as 10255
- In "Authentication" tab provide details noted down in previous Step 2
- Check "Perform authentication"
- Add Database as "admin"
- Add Username as "https://localhost:8081"
- Add Password as "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
- In "TLS" tab provide
- Check "Use TLS protocol"
- From Authentication Method dropdown select "Self-signed Certificate"
- Click on "Test" button.
- It should successfully connects to localhost:10255 via TLS tunnel
- It should successfully authorise to database "admin"
- Click on "Save" button
- Click on "Connect" button.
- It will show the admin database and its related collections.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.