strapi mongo flutter app connection error - mongodb

When I install strapi via npm, then run "strapi new server" and then try to connect to mongodb atlas; It shows the following error.
(node:12564) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
⛔️ Connection test failed: failed to connect to server [oriapp-shard-00-01.pjvsw.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to oriapp-shard-00-01.pjvsw.mongodb.net:27017 closed
at TLSSocket. (C:\Users\Sharm\AppData\Local\Temp\strapi236c8a243294\node_modules\strapi-connector-mongoose\node_modules\mongodb\lib\core\connection\connection.js:356:9)
at Object.onceWrapper (events.js:422:26)
at TLSSocket.emit (events.js:315:20)
at TLSSocket.EventEmitter.emit (domain.js:483:12)
at net.js:674:12
at TCP.done (_tls_wrap.js:567:7) {
[Symbol(mongoErrorContextSymbol)]: {}
}]

So , the solution to the above problem:
Reinstall strapi using npm or yarn or any other package manager.
The ip whitelist in mongodb atlas in your cluster should have the ip address of your system.
when aysnchronous function is defined use Ipv4 in place of "localhost:1337".
Thus one will be good to go.

Related

connecting to mongodb replicaSet with nestjs and typeorm is not working

problem
I'm trying to connect to mongodb with nestjs(^8.2.3) and typeorm(^0.2.28)
In test environment, connecting to mongodb standalone server is working. For your information, node mongodb library version is ^3.6.2.
production sample code(nestjs server)
I referred the typeorm code to write mongodb options
import { TypeOrmModule } from '#nestjs/typeorm';
import { MongoConnectionOptions } from 'typeorm/driver/mongodb/MongoConnectionOptions';
export const configForOrmModule = TypeOrmModule.forRootAsync({
imports: [],
useFactory: async () => {
const mongodbConfig: MongoConnectionOptions = {
type: 'mongodb',
username,
// for replicaSet (production)
hostReplicaSet: 'server1.example.com:20723,server2.example.com:20723,server.example.com:20723',
replicaSet: 'replicaSetName'
port: Number(port),
password: encodeURIComponent(password),
database,
authSource,
synchronize: true,
useUnifiedTopology: true,
entities: [Something],
};
return mongodbConfig;
},
inject: [],
});
But in production environment, when nestjs server try to connect to mongodb replicaSet, the server get this server selection loop error message over and over again like below. Interesting thing was the domain that the server tried to connect was different from replicaSet hosts(ex. another-hostname not included in server1.example.com:20723,server2.example.com:20723,server.example.com:20723). (+ edited: the another hostname is actual physical server indicated by the dns(server.example.com))
[39m01/28/2022, 2:39:16 AM [31m ERROR[39m [38;5;3m[TypeOrmModule] [39m[31mUnable to connect to the database. Retrying (3)...[39m
MongoServerSelectionError: getaddrinfo ENOTFOUND <another-hostname>
at Timeout._onTimeout (/home/node/app/node_modules/mongodb/lib/core/sdam/topology.js:430:30)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
what I’ve tried but these not worked
remove useUnifiedTopology: true option
downgrade mongodb library version to 3.5.11 (I've read in mongodb community there are something bug with topology after 3.6 version)
use host option not the hostReplicaSet
if you need more information, please tell me. thank you for your helping.
It was kubernates DNS issue. The hostReplicaSet server1.example.com:20723,... is resolved to host1 (physical server name. without example.com) but, k8s doesn't know it. so connection was failed.
there are two options
update kubernates /etc/hosts setting to add host1 -> host1.example.com
or update mongodb hostname host1 -> host1.example.com

Mongodb connectionString can't connect

I can connect via Mongodb COMPASS using my username and password but apparently i can't connect it to my website.
mongodb://localhost:27017/mydb works fine in connection string but not atlas/online cluster
{"connectionString":"mongodb+srv://myuser:mypass#thiscluster.azure.mongodb.net/mydb?retryWrites=true&w=majority"
,"secret":""}
Error :
Server listening on port 3000
Unhandled rejection MongoError: not authorized on admin to execute command { lis
tIndexes: "sessions", cursor: { } }
at Function.MongoError.create (C:\Users\user\Documents\GitHub\meanie\serv
er\node_modules\mongodb-core\lib\error.js:31:11)
at queryCallback (C:\Users\user\Documents\GitHub\meanie\server\node_modul
es\mongodb-core\lib\cursor.js:212:36)
at C:\Users\user\Documents\GitHub\meanie\server\node_modules\mongodb-core
\lib\connection\pool.js:469:18
at processTicksAndRejections (internal/process/task_queues.js:79:11)
I am using MEANIE STACK BLOG
Reference : Cloud mongodb guide
mongodb+srv://:#thiscluster.azure.mongodb.net/?retryWrites=true&w=majority
Other reference : https://docs.mongodb.com/manual/reference/connection-string/
SOLVED
config.json / node's "connectionString" can't be parsed using mongo+srv://user:pw#thiscluster.mongodb.com/mydb?thisoptions
node version i'm using is 2.2 12
fixed via :
"connectionString":"mongodb://user:pass#test-shard-00-00-sample.azure.mongodb.net:27017,test-shard-00-01-sample.azure.mongodb.net:27017,test-shard-00-02-sample.azure.mongodb.net:27017/THISDB?ssl=true&replicaSet=Test-shard-0&authSource=admin&retryWrites=true&w=majority",

parse server migration cannot connect to mongo

This is related to migration to parse server from api.parse.com.
On windows server, installed mongo db and nodeJS.
Installed Python.
Installed Parse Server.
Getting following error messages.
StyleChat is the name of the app.
http://localhost:1337/stylechat
parse-server-example running on port 1337. info: Parse LiveQuery
Server starts running warn: Unable to ensure uniqueness for usernames:
Error: read ECONNRESET
at exports._errnoException (util.js:1036:11)
at TCP.onread (net.js:564:26) warn: Unable to ensure uniqueness for user email addresses: Error: read ECONNRESET
at exports._errnoException (util.js:1036:11)
at TCP.onread (net.js:564:26) (node:252160) UnhandledPromiseRejectionWarning: Unhandled promise rejection
(rejection id: 4): MongoError: read ECONNRESET (node:252160)
UnhandledPromiseRej
if you run nodejs on window, you should use iisnode to run nodejs on iis.
i found this here
have fun.

SailsJS deployment to Heroku, connect to Mongolabs MongoDB

I am right now attempting my first Heroku deployment of a SailsJS API. My app uses SailsJS v0.11 andsails-mongo 0.11.2.
I have updated config/connections.js to include the connection information to MongoDB database I have hosted for free at Mongolab.
mongodb: {
adapter: 'sails-mongo',
url: "mongodb://db-user:password123#ds047812.mongolab.com:47812/testing-db"
}
Also updated config/models.js to point to that adapter.
module.exports.models = {
connection: 'mongodb',
migrate: 'safe'
};
This is basically all I have changed from running the code locally, when I deploy to Heroku the app crashes and I get this error...
/home/zacharyhustles/smallChangeAPI/node_modules/connect-mongo/lib/connect-mongo.js:186
throw err;
^
at Socket.emit (events.js:107:17)
2015-07-08T19:37:00.778316+00:00 app[web.1]:
at Socket.<anonymous> (/app/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/connection.js:534:10)
Error: Error connecting to database: failed to connect to [localhost:27017]
How do I get rid of this, and make sure Sails does not try connecting to localhost db?
Ok, the problem was with storing sessions.
My solution was to setup a Redis database to store sessions.
In config/sessions.js make sure everything is commented out except for the method you want for session store.
Mine looked like this:
adapter: 'redis',
host: 'example.redistogo.com',
port: 1111,
db: '/redistogo',
pass: 'XXXXXYYYYYYXYXYXYYX',
This solved my posted problem, hope this helps another person out.

Error connecting meteor to external mongodb

I have a meteor web app that connects to a mongohq database. It's working correctly on heroku, but I can't get it to work on my localhost. It was working on localhost yesterday, but not today.
To be certain, I just ran a git clone in a new folder. Even this clone is throwing errors on localhost. Here's my terminal (FYI, I'm on a windows 8.1 machine that is running an Ubuntu virtual box; also, I've removed the username / password from the log, below):
adam#adam-VirtualBox:~/resSingleTestV2/faze1tables$ export MONGO_URL=mongodb://<username>:<password>#oceanic.mongohq.com:10033/test_db
adam#adam-VirtualBox:~/resSingleTestV2/faze1tables$ meteor
[[[[[ ~/resSingleTestV2/faze1tables ]]]]]
=> Started proxy.
=> Started your app.
=> App running at: http://localhost:3000/
I20140511-12:53:43.438(-4)? Exception in callback of async function: Error: failed to connect to [oceanic.mongohq.com:10033]
I20140511-12:53:43.637(-4)? at null.<anonymous> (/home/adam/.meteor/packages/mongo-livedata/0120179b5c/npm/node_modules/mongodb/lib/mongodb/connection/server.js:536:74)
I20140511-12:53:43.640(-4)? at EventEmitter.emit (events.js:106:17)
I20140511-12:53:43.641(-4)? at null.<anonymous> (/home/adam/.meteor/packages/mongo-livedata/0120179b5c/npm/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:150:15)
I20140511-12:53:43.641(-4)? at EventEmitter.emit (events.js:98:17)
I20140511-12:53:43.643(-4)? at Socket.<anonymous> (/home/adam/.meteor/packages/mongo-livedata/0120179b5c/npm/node_modules/mongodb/lib/mongodb/connection/connection.js:516:10)
I20140511-12:53:43.643(-4)? at Socket.EventEmitter.emit (events.js:95:17)
I20140511-12:53:43.644(-4)? at net.js:440:14
I20140511-12:53:43.644(-4)? at process._tickCallback (node.js:415:13)
Any help appreciated. Thanks.
I'm connecting via my school's wifi. Turns out they must've done something to prevent me from connecting to mongoHQ because I'm able to connect via other networks.
Strange that it worked for a day or two and then stopped.