MongoServerSelectionError: connection <monitor> to xx.xxx.xxx.xxx:27017 closed (whitelisting IP and opening the port didn't work) - database

i'm learning MongoDB and i'm sorry to bother you but i'm getting this error:
MongoServerSelectionError: connection <monitor> to xx.xxx.xxx.xxx:27017 closed
at Timeout._onTimeout (C:\...\node_modules\mongodb\lib\sdam\topology.js:305:38)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
reason: TopologyDescription {
type: 'ReplicaSetNoPrimary',
servers: Map(3) {
'ac-c9obg9r-shard-00-00.onq7cwz.mongodb.net:27017' => [ServerDescription],
'ac-c9obg9r-shard-00-02.onq7cwz.mongodb.net:27017' => [ServerDescription],
'ac-c9obg9r-shard-00-01.onq7cwz.mongodb.net:27017' => [ServerDescription]
},
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: 'atlas-up12ch-shard-0',
logicalSessionTimeoutMinutes: undefined
},
code: undefined,
[Symbol(errorLabels)]: Set(0) {}
}
I have tried to enable the port 27017 and resetting the ip in the network access tab (was white listed already), but no luck, error persists. Reinstalled the modules I used, and nothing.
My code was working yesterday, but after a Windows update i can't connect (that's why i thought it was the port).
The digits I replaced xx.xxx.xxx.xxx:27017 are not my ip number, i don't know if that helps.
If u have any ideas, I apreciate your input.

MongoServerSelectionError: connection <monitor> to xx.xxx.xxx.xxx:27017 closed
at Timeout._onTimeout (C:\...\node_modules\mongodb\lib\sdam\topology.js:305:38)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7)
I had this same error while trying to connect to MongoDB with a new Node server.
See if you have changed your network connection to a diferent network than the one you have whitelisted in MongoDB.
If so, whitelist the current IP adress in mongoDB.
(PS: I see you have already tried resetting the IP address in the Network Access tab, but check again. This was how i fixed it.)
Also, check and see if the .env file variables are correctly declared with MongoDB link and also change the password and database name.
Still if the issue is not solved, I would suggest you to delete the old cluster and create a new one in MongoDB. Also re-initialise node and the packages.
Hope this solves your problem.

For me this error was occurring because my connection string was wrong.To be very specific - I copied the sample connection string from a course I was learning and just replaced the username and password with my credentials. So, the credentials were right but not the rest of the connection string.
Just for the sake of understanding. Please see below :
mongodb+srv://myusername:mypassword#courseproject.h1mpg.mongodb.net/?retryWrites=true&w=majority"
myusername and mypassword are correct i.e belong to the cluster in my atlas account but the rest of the string is wrong as I copied it from somewhere instead of copying it from my own MongoDB atlas account.
So please make sure to double check if your entire connection string is correct.

import { MongoClient } from 'mongodb'
const uri = process.env.MONGODB_URI
const options = {
useNewUrlParser: true,
useUnifiedTopology: true,
}
client = new MongoClient(uri, options)
clientPromise = client.connect();
export default clientPromise
Inside your .env you could insert something like this:
MONGODB_URI=mongodb+srv://username:password#name-of-cluster.i43pl8d.mongodb.net/DatabaseName?retryWrites=true&w=majority
Code snippet for connnecting mongodb will be available at https://cloud.mongodb.com/, navigate to your cluster and click connect then click Connect your application.
Finally copy code snippet whatever you get at your time of mongodb version after choosing include full driver code example and implement it into your application:

Related

How to set Ipv4 addresses with dbus-python (Hotspot and ethernet)

(fairly new to networking)
I'm trying to setup a small, yet somewhat complicated network settings on my ubuntu 18.04 machine.
The topology of the network: Ubuntu machine (called "the server") will act as the DHCP server for both hotspot and ethernet. connected to the ubuntu machine are 2 ubuntu machine clients and a camera.
I've implemented "the server" with python-dbus library, to set up/down a hotspot connection, which works as intended. but my problem is how to manage the ip addresses and the routing.
i'll elaborate on 2 problems i am facing:
in order to change the ipv4 address for the Hotspot AP, i found out i could edit a file: "/etc/NetworkManager/system-connections/", adding another line: "address1=X.Y.Z.W" (my desired ip address).
but editing the file isn't the proper way for my requirements, i would rather do it from the code itself. which changes do i need to make to the code in order to make the same changes?
this is how the code connection object of dbus looks like:
def get_hotspot_struct(iface, uuid, ssid, password):
s_con = dbus.Dictionary({
'type': '802-11-wireless',
'uuid': uuid,
'id': 'PixellotHotspot',
'interface-name': iface,
})
s_wifi = dbus.Dictionary({
'ssid': dbus.ByteArray(ssid.encode()),
'mode': 'ap',
'band': 'bg',
'channel': dbus.UInt32(1),
})
s_wsec = dbus.Dictionary({
'key-mgmt': 'wpa-psk',
'psk': password,
})
s_ipv4 = dbus.Dictionary({
'method': 'shared',
})
s_ipv6 = dbus.Dictionary({
'method': 'ignore',
})
con = dbus.Dictionary({
'connection': s_con,
'802-11-wireless': s_wifi,
'802-11-wireless-security': s_wsec,
'ipv4': s_ipv4,
'ipv6': s_ipv6,
})
logger.info('Getting hotspot connection template')
logger.info(con)
return con
Can i do the same for ethernet wired connections?
so far what ive figured is that I can edit "/etc/netplan/01-netconf.yaml" in order to set dhcp to false, and se an ip "X.Y.Z.W" (desired) for ethernet interface eth0.
but that seem to only work on the server, when i connect the ubuntu clients with ethernet wire to the server, the server wont give the clients any ip at all.
It does for the hotspot, but not for the ethernet.
I know my problem is very specific and all-over-the-place, but i would appreciate any help. Post here/sendme email/ Facebook me(Yves Halimi) if you have knowledge about this issue. Will compensate help!!
The D-Bus API is documented in man nm-settings-dbus.
To NetworkManager, it's always about creating connection profiles and activating them. So if you have code that can create one profile, another profile works basically the same -- just some keys will be different.
I find it helpful to use one of the other NetworkManager clients, and compare with what they do. For example, you could also just create the profile with nmcli connection add type ..., then get the D-Bus path via nmcli -f all connection show and finally, look at how the profiles looks on D-Bus:
busctl -j call org.freedesktop.NetworkManager /org/freedesktop/NetworkManager/Settings/1 org.freedesktop.NetworkManager.Settings.Connection GetSettings
See examples upstream: python+dbus
Maybe you'll find it easier to use python + pygobject + libnm. In that case, see examples here. The main downside is that you'll have an additional dependency (pygobject). libnm isn't an additional dependency, you'll already have that if you use NetworkManager.

How to transalte messages that comes from server in react native app

I'm building a react-native app with spanish as default language, the problem is that I'm using a open source backend service to serve data and this data comes is in english by default. What I want is to transalate this data/messages that comes from server in my react-native app to show to the user the messages in spanish not in english.
This is the first time I am doing this process and it is not clear to me what are the steps or the flow that is generally followed for this kind of proces(translate messages that comes from server in my app).
You have many approaches to such a thing one comes to mind is
Catch the error/api response message which mostly server error messages comes in codes and messages.
set a condition statement if code equal 2 that means the server is down for example
Example:
You made a request to the server and there was an error with the server let say wrong username and password, now the server returns a message and a error code you have to get the code or the message and show your own message
.....made the request the server returned
{ code: 192, message: Wrong username/Password }
now in your code you will do the following
if(code == 192){
...do your message
}
P.S this is just on top my head since you didn't share any codes or responses from your server.
UPDATE :
If you want to translate all your strings/messages that comes from the server you would need to do another approche something like this
Create a file contain all the strings/codes from the server
compare messages/code comes from the server and the file will return the text you want
{ "102": "Hola", "103": "Bien", "104": "Nada", "105": "Si", }
now this file contain the error/message code all you have to do is when you receive the code grab the message from this file
let translation = {
"101": "Hola",
"102":"Si"
};
translation["102"]; // Result will be Si
Now this is the most accurate approach but you have to know all the messages/codes comes from the server, now if you want something to translate on the fly you might wanna use translation library and may not be accurate translation

Pick up connection if there is a disconnect

I make use of this specific version: https://github.com/patriksimek/node-mssql/tree/v3.3.0#multiple-connections of the SQL Server npm package.
I have been looking through the documentation of tedious (the underlying lib) and Microsofts documentation (see the github link above).
I couldn't find anything that does something simple like getCurrentConnection, or getConnectionStatus or anything similar.
I had two ways to solve this problem but I'm not happy with both of them so that's why I'm asking here.
My first approach was to set a timeout and let the connect function call itself on each catch(err).
The second one was to handle this in the middleware but then if all is working fine it will make a connection to SQL on every request and closing that connection again.
My middleware function:
api.use(function(err, req, res, next){
sql.close();
sql.connect(config.database).then(() => {
next();
}).catch(function(err) {
sql.close();
server.main();
});
});
I want to, if possible pick up the connection instead of closing and starting a new one with regards to when the server or the database crashes I still have some data from the existing function.
By the help of Arnold I got to understand the mssql package and it's inner workings a lot better.
Therefor I came up with the following solution to my problem.
let intervalFunction;
const INTERVAL_DURATION = 4000;
if (require.main === module){
console.log("Listening on http://localhost:" + config.port + " ...");
app.listen(config.port);
// try to connect to db and fire main on succes.
intervalFunction = setInterval(()=> getConnection(), INTERVAL_DURATION);
}
function getConnection() {
sql.close();
sql.connect(config.database).then(() => {
sql.close();
clearInterval(intervalFunction);
main();
}).catch(function(err) {
console.error(err);
console.log(`DB connection will be tried again in ${INTERVAL_DURATION}ms`)
sql.close();
});
}
Once the initial connection has been made but it got lost in the meantime the pool will pick up the connection automatically and handle your connections
If I understood you correctly, you basically want to reuse connections. Tedious has built-in connection pooling, so you don't have to worry about re-using them:
var config = {
user: '...',
password: '...',
server: 'localhost',
database: '...',
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 30000
}
}
In the example above (just copied from the GitHub URL you've posted), there will be 10 connections in the pool ready to use. Here's the beauty: the pool manager will handle all connection use and re-use for you, i.e., the number of connections are elastic based on your app's needs.
As you've mentioned, what about DB crashes? That too is built-in: connection health-check:
Internally, each Connection instance is a separate pool of TDS
connections. Once you create a new Request/Transaction/Prepared
Statement, a new TDS connection is acquired from the pool and reserved
for desired action. Once the action is complete, connection is
released back to the pool. Connection health check is built-in so once
the dead connection is discovered, it is immediately replaced with a
new one.
I hope this helps!

Using satellizer to login via facebook and sending user information to server

I am attempting to send back to the sever the user information from satellizer.
I believe the call is as per this url:
https://github.com/sahat/satellizer#authauthenticatename-userdata
$auth.authenticate(name, [userData])
However when I use it :
$auth.authenticate('facebook', ['userData'])
my sever receives :
{ '0': 'userData',
code: 'AQB8ofHRuC',
clientId: '1625070294abcdef',
redirectUri: 'http://localhost:3000/' }
instead of actually receiving the userData.. what am i missing here ?
[userdata] is a kind of custom data, this means that you can put in it your data (some values). When you put $auth.authenticate('facebook', ['userData']) you put an array with one string element 'userData'. I think that it make sens to grab info on server by uid.
UPDATE
I found recent a link
https://github.com/sahat/satellizer/blob/master/examples/server/node/server.js#L537. You can translate node js code in your server programming language code.

D3 Connection issue using mvsp java api

I am trying to connect to D3 Database with MVSP java api. So far:
I have downloaded the mvapi.jar
added it in project lib folder
written the sample code for connection inside main method
String url = "jdbc:mv:d3:hostname:portNo";
Properties props = new Properties();
props.setProperty("username", "");
props.setProperty("password", "");
String account = "AGCO";
String password = "";
MVConnection connection = null;
try {
// Getting error at this point
connection = new MVConnection(url,props);
MVStatement mvStatement = connection.createStatement();
connection.logTo(account,password);
MVResultSet results = mvStatement.executeQuery(query);
}
com.tigr.mvapi.exceptions.MVException: server error with errorCode 1023.
I checked the console but I'm not able to figure out the actual cause or whether I am entering the wrong username, password.
Please suggest what I am doing wrong.
First, you have to set a breakpoint or trace which function is throwing the errors. Then check the routes, (FileName) probably you will have much more experience than I do, but keep in mind that giving the full route ("account,filename," where the last comma is important) is never a bad idea while keep you safer and is mandatory if the filename is in a different account that you are logged to.
And like always please verify these things:
You have enough licenses. Try to close any terminal you have opened for testing your queries. Yes you know is true. One connection one license. Sometimes MVSP let you two under the same IP but chek this.
MVSP service is running. See Pick D3 documentation.
Your USER and ACCOUNT are both ENABLED to access in the MVSP server otherwise you won't be able to access these files or login with the user through the API. See the documentation to enable in the MVSP.Menu account.
I hope this helps.

Resources