Reputation: 64
I am trying to connect to CosmosDB, I use connection string from Quick Start, it is working fine on my localhost but once I deploy I get
{
name: "MongoError",
message: "Database account is not found"
}
var express = require('express'),
mongoose = require('mongoose');
mongoUri = "mongodb://dbaccount:pass@dbhost:port/dbNAME?ssl=true';
options = {
"useMongoClient":true,
"promiseLibrary": global.Promise,
"ssl": true
}
mongoose.Promise = global.Promise;
var db = mongoose.connect(mongoUri,options)
I've checked connection string. I can connect on my localhost also I can connect to db using Robo 3T.
Upvotes: 1
Views: 2546
Reputation: 261
I was having the same issue. In your Azure Cosmos DB you just have to enable this:
This will allow other Azure resources (such a Web App) to access your database.
Upvotes: 0
Reputation: 378
TL;DR: Add the IP from your web app on Azure to the IP Access Control List on you Firewall on your DB.
I had exactly the same issue, I could connect locally and with Robo 3T, but once I deployed the app on Azure I received this error:
MongoError: Database account is not found
at Function.MongoError.create (D:\home\site\wwwroot\node_modules\mongodb-core\lib\error.js:31:11)
at D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\pool.js:497:72
at authenticateStragglers (D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\pool.js:443:16)
at Connection.messageHandler (D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\pool.js:477:5)
at TLSSocket.<anonymous> (D:\home\site\wwwroot\node_modules\mongodb-core\lib\connection\connection.js:331:22)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at TLSSocket.Readable.push (_stream_readable.js:208:10)
at TLSWrap.onread (net.js:594:20)
So chances are high, that something with the firewall settings on Azure is wrong.
For me, I disabled my the IP Access Control on the db on Azure and the error disappeared and everything worked as expected. I turned IP Access Control back on and added the IP from the web app, to allow access. That should do the trick. I think you can access from your localhost because your local IP is already added as default for development purposes.
See this Microsoft Doc for further information: https://learn.microsoft.com/en-us/azure/cosmos-db/firewall-support
Upvotes: 4