I have created a free cluster for mongodb atlas. Under that cluster I have created a database and a collection to test things out. As I was using node js driver 4.0 or above, this is the connection string I got:
mongodb+srv://myName:myPass#cluster0.2sjva.mongodb.net/myDb?retryWrites=true&w=majority
This is my backend code:
const { MongoClient } = require("mongodb");
// Connection URI
const uri =
"mongodb+srv://myName:myPass#cluster0.2sjva.mongodb.net/myDb?retryWrites=true&w=majority";
// Create a new MongoClient
const client = new MongoClient(uri);
async function run() {
try {
// Connect the client to the server
await client.connect();
// Establish and verify connection
await client.db("myDb").command({ ping: 1 });
console.log("Connected successfully to server");
} finally {
// Ensures that the client will close when you finish/error
await client.close();
}
}
run().catch(console.dir);
But when I run this code, I get this following error:
Error: querySrv ECONNREFUSED _mongodb._tcp.cluster0.2sjva.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:210:19) {
errno: undefined,
code: 'ECONNREFUSED',
syscall: 'querySrv',
hostname: '_mongodb._tcp.cluster0.2sjva.mongodb.net'
}
Here is some information I can provide:
I have whitelisted my current Ip address, After this error I used 0.0.0.0. But the problem persists.
Os: Arch linux
I have also tried to use this connection string for older driver version: mongodb://... and that worked.
My question: why connection string for node js driver version > 4.0 doesn't work in my case?
Thank you for reading!
I tried to connect the MongoDB Atlas to my Deno Application using https://deno.land/x/mongo#v0.21.2 framework. I tried the below code to run my application. but I get an error No such host is known. (os error 11001) What went wrong here
Error
error: Uncaught Error: No such host is known. (os error 11001)
at unwrapResponse (rt\10_dispatch_json.js:24:13)
at sendAsync (rt\10_dispatch_json.js:75:12)
at async Object.connect (rt\30_net.js:221:13)
at async MongoClient.connect (client.ts:41:14)
at async mongodb.ts:33:1
Mongodb.ts File
import { MongoClient } from "https://deno.land/x/mongo#v0.21.0/mod.ts";
const client1 = new MongoClient();
await client1.connect("mongodb+srv://user1:MYPASSWORD#cluster0.hmdnu.mongodb.net/TestingDB?retryWrites=true&w=majority");
const db = client1.database("TestingDB");
export default db;
I used this command to run my server
deno run --allow-net --allow-write --allow-read --allow-plugin --unstable server.ts
I fixed this using https://www.youtube.com/watch?v=hhdhydffKKE this video reference
Follow these steps to fix this
import { MongoClient } from "https://deno.land/x/mongo#v0.21.0/mod.ts";
const client1 = new MongoClient();
await client.connect({
db: "<db>",
tls: true,
servers: [
{
host: "<host>",
port: 27017,
},
],
credential: {
username: "<user>",
password: "<password>",
db: "<db>",
mechanism: "SCRAM-SHA-1",
},
});
const db = client1.database("TestingDB");
export default db;
This is not mentions in the document, but this will help to fix the issue
<db> is the database name, you can get the database name by following these steps
Step-1
Step-2
To find the <host> follow these steps
Step -1
Step -2
Step -3
the issue:
This what happens when I curl the endpoint http://ip/getuser/
UnhandledPromiseRejectionWarning: MongoParseError: URI malformed, cannot be parsed
at parseConnectionString (/app/node_modules/mongodb/lib/core/uri_parser.js:542:21)
at connect (/app/node_modules/mongodb/lib/operations/connect.js:272:3)
at cb (/app/node_modules/mongodb/lib/mongo_client.js:221:5)
at maybePromise (/app/node_modules/mongodb/lib/utils.js:714:3)
at MongoClient.connect (/app/node_modules/mongodb/lib/mongo_client.js:217:10)
at Function.MongoClient.connect (/app/node_modules/mongodb/lib/mongo_client.js:427:22)
at exports.IsCardActivated (/app/routes/index.js:47:45)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at next (/app/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing in
side of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (re
jection id: 2)
(node:1) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejectio
ns that are not handled will terminate the Node.js process with a non-zero exit code.
router/getuserbydetails
const MongoClient = require('mongodb').MongoClient;
require('dotenv').config()
function connectUrl() {
return process.env.url;
}
exports.GetUserDetails = async (req, res) => {
....
if (!client) client = await MongoClient.connect(connectUrl(), { useNewUrlParser: true })
const db = client.db(getDatabaseName());
....
};
./index.js
var user= require('./routes/user/index');
app.get('/getuser', user.getuser);
Dockerfile
FROM node:10
ENV NODE_ENV="production"
COPY . /app
WORKDIR /app
RUN npm install
ENV PORT 80
EXPOSE 80
CMD [ "node", "index.js" ]
Google Platform: GCE instance setting:
Note:
firewall:
allow 443, 80
using LB on in front of the application.
This application works fine locally I'm wondering where it might be going wrong.
I have followed and finished the tutorial
https://medium.com/#malliksarvepalli/hyperledger-fabric-1-2-on-multiple-hosts-using-docker-swarm-and-compose-11c13635e69e
and I have 3 hosts connected and all services are up. I had the correct result when I run the ./script.sh in the PC2 host.
Now I am following the next tutorial which is:
https://medium.com/#malliksarvepalli/hyperledger-explorer-with-fabric-1-2-running-on-multiple-hosts-89c5af691b7e
Can anyone please enlighten me in this tutorial? I have figured out that I should create a new host with ubuntu 16.04 and install the following prerequites:
nodejs 8.11.x
PostgreSQL 9.5 or greater
Jq
Am I right?
And in the exploreconfig.json I updated postgres variables:
host:192.168.1.136(4th's vm ip),
port:5432,
username:postgres,
password:psql,
database:fabric
Are they correct?
I have also modified Orderer, Org1 [peer0 & peer1), Org2(peer0 & peer1) IP address in config.json file with the ips of first three Vms where the network is up and running.
And follow the rest instructions and tests but when I run the command ./start.sh I have logs in console which are:
false 'ssl-certs' '/home/database/blockchain-explorer/ssl-certs'
postgres://christy:christy#192.168.1.136:5432/fabric
error when connecting to db: { Error: connect ECONNREFUSED 192.168.1.136:5432
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '192.168.1.136',
port: 5432 }
******* Initialization started for hyperledger fabric platform ******, {
'network-1':
{ version: '1.0',
clients: { 'client-1': [Object] },
channels: { mychannel: [Object] },
organizations: { Org1MSP: [Object], Org2MSP: [Object], OrdererMSP:
[Object] },
peers:
{ 'peer0.org1.ntua.com': [Object],
'peer1.org1.ntua.com': [Object],
'peer0.org2.ntua.com': [Object],
'peer1.org2.ntua.com': [Object] },
orderers: { 'orderer.ntua.com': [Object] } },
'network-2': {} }
client_configs.name undefined client_configs.profile undefined
FabricUtils.createFabricClient
<<<<<<<<<<<<<<<<<<<<<<<<<< Explorer Error >>>>>>>>>>>>>>>>>>>>>
Error : [ 'Invalid platform configuration, Please check the log' ]
error when connecting to db: TypeError: Cannot read property 'on' of
undefined
at Timeout.handleDisconnect [as _onTimeout] (/home/database/blockchain-
explorer/app/persistence/postgreSQL/PgService.js:68:16)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
<<<<<<<<<<<<<<<<<<<<<<<<<< Explorer Error >>>>>>>>>>>>>>>>>>>>>
TypeError: "callback" argument must be a function
at setTimeout (timers.js:450:11)
at Timeout.handleDisconnect [as _onTimeout] (/home/database/blockchain-
explorer/app/persistence/postgreSQL/PgService.js:85:5)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
Received kill signal, shutting down gracefully
Closed out connections
false 'ssl-certs' '/home/database/blockchain-explorer/ssl-certs'
postgres://christy:christy#192.168.1.136:5432/fabric
error when connecting to db: { Error: connect ECONNREFUSED 192.168.1.136:5432
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '192.168.1.136',
port: 5432 }
******* Initialization started for hyperledger fabric platform ******,
{
'network-1':
{ version: '1.0',
clients: { 'client-1': [Object] },
channels: { mychannel: [Object] },
organizations: { Org1MSP: [Object], Org2MSP: [Object], OrdererMSP:
[Object] },
peers:
{ 'peer0.org1.ntua.com': [Object],
'peer1.org1.ntua.com': [Object],
'peer0.org2.ntua.com': [Object],
'peer1.org2.ntua.com': [Object] },
orderers: { 'orderer.ntua.com': [Object] } },
'network-2': {} }
client_configs.name undefined client_configs.profile undefined
FabricUtils.createFabricClient
<<<<<<<<<<<<<<<<<<<<<<<<<< Explorer Error >>>>>>>>>>>>>>>>>>>>>
Error : [ 'Invalid platform configuration, Please check the log' ]
error when connecting to db: TypeError: Cannot read property 'on' of
undefined
at Timeout.handleDisconnect [as _onTimeout] (/home/database/blockchain-
explorer/app/persistence/postgreSQL/PgService.js:68:16)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
<<<<<<<<<<<<<<<<<<<<<<<<<< Explorer Error >>>>>>>>>>>>>>>>>>>>>
TypeError: "callback" argument must be a function
at setTimeout (timers.js:450:11)
at Timeout.handleDisconnect [as _onTimeout] (/home/database/blockchain-
explorer/app/persistence/postgreSQL/PgService.js:85:5)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
Received kill signal, shutting down gracefully
Received kill signal, shutting down gracefully
Closed out connections
If the other logs are also needed please let me know. Any help will be helpful. Thanks a lot.
I can give you some aspects to be checked on your environment.
First you need to do check if you are able to access postgresql DB(4th's vm) from the vm where you are trying to launch Hyperledger Explorer. If not, you need to change your postgres configuration (postgresql.conf/pg_hba.conf) for enabling external access, I think.
$ sudo -u postgres psql -h 192.168.1.136 -d fabric -c 'table peer'
Second, please confirm that you did run ./createdb.sh on 4th VM. If you changed database name, you also need to align the script
$ cd app/persistence/fabric/postgreSQL/db/
$ ./createdb.sh
My sails application not able to connect to locally running mongo db instance
local.js is like below
module.exports.connections = {
sailsMongoDBServer: {
adapter: 'sails-mongo',
host: '127.0.0.1',
port: 27017,
database: 'dp-manager-db'
}
}
Error :
2019-03-06T12:32:01.081Z - error:
{ message:
'The hook `orm` is taking too long to load.\nMake sure it is triggering its `initialize()` callback, or else set `sails.config.orm._hookTimeout to a higher value (currently 20000)',
stack:
'Error: The hook `orm` is taking too long to load.\nMake sure it is triggering its `initialize()` callback, or else set `sails.config.orm._hookTimeout to a higher value (currently 20000)\n at Timeout.tooLong [as _onTimeout] (E:\\workspace_DpForm\\Eclipse\\dpm-app\\node_modules\\sails\\lib\\app\\private\\loadHooks.js:85:21)\n at ontimeout (timers.js:436:11)\n at tryOnTimeout (timers.js:300:5)\n at listOnTimeout (timers.js:263:5)\n at Timer.processTimers (timers.js:223:10)',
code: 'E_HOOK_TIMEOUT' }
2019-03-06T12:32:03.521Z - error: A hook (`orm`) failed to load!
E:\workspace_DpForm\Eclipse\dpm-app\node_modules\mongodb\lib\mongo_client.js:224
throw err