how do i connect google app engine with mongolab - javascript

I want to use mongolab database in my website that i deploy on google app engine.
i go through many tutorials but i still not get it that how mlab uri which contains our username and password connect with google app engine?
in my node js file i use mongoose for connect to database but it gives me authentication failed error. do i need additional setup for connect mlab?
mongoose.connect(
"mongodb://username:password#ds243212.mlab.com:43212/userinfo",
{useNewUrlParser : true},
{useMongoClient: true},
function(err , db){
if(err) console.log(err);
console.log("connection success");
}
this is simple way i tried.

Related

Cannot connect to Cloud SQL SQL Server from Cloud Functions using private IP

I have a Cloud Function that I want to connect to a SQL Server Instance.
By documentation, you can only connect using a private IP.
Everytime I try to connect I get the error:
ERROR: (gcloud.functions.call) ResponseError: status=[400], code=[Bad Request], message=
[Function failed on loading user code. Error message: {"code":"ELOGIN","originalError":
{"message":"Logon failed for login 'sqlserver' due to trigger execution.","code":"ELOGIN"},"name":"ConnectionError"}]
My Cloud Function code:
const sql = require('mssql');
exports.test = (req, res) => {
const config = {
user: 'sqlserver',
password: 'test',
server: '10.60.80.3',
port:1433,
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 30000
}
};
const pool = new sql.ConnectionPool(config);
pool.connect()
.then(() => {
res.status(200).send({message: "Connection ready."});
})
.catch(err => {
res.status(500).send(err);
pool.close();
});
};
I have done the following configurations:
VPC Connector on default network
The default network was applied to Private IP configuration of SQL Server instance.
SQL Server Instance configuration
When creating the Cloud Function, you are required to select a service account and a VPC connector. I chose the connect-ip-sql connector. For service account, I tried with App Engine Default Service Account and Compute Engine Service Account ( both given the role of Cloud SQL client). Same error.
It seems to be a problem with SQL Server login and not about finding the network since I tried changing the network (setting the SQL Server in another VPC) and it returned CONNECTION TIMEOUT.
I can login using public ip in my SSMS using the default username-password. When I run the query:
select * from sys.server_triggers
There are three server triggers but there is no information what they do.
gcloudsql_RoleManagement
TRG_ProtectDropCustRootLogin
TRG_DisableRemoteConnectionForDbRoot
You cannot drop or change them, because Cloud SQL is a managed service and you have no access on the 'sa' superuser.
It would be best to request Google Cloud Support assistance (public tracker is mostly for bugs) since it could be a lot of things that could go wrong here.
But with that said, I assume you have the following in place:
GCP firewall rules that allows traffic from/to your Cloud Funtion and Cloud SQL MSSQL
Cloud SQL uses VPC peering for RFC-1918 connections, so I assume that your VPC connector route is there as exported and your MSSQL route is there as well as imported
Your Cloud Funtion VPC connector is in the same region as your Cloud MSSQL
I would recommend for you to enable flow logs and GCP firewall logs, also running connectivity test can also give you a hint on what might be blocking you

communicate between apps over network

I'm trying to build an app that would be able query a database over wifi, I think I'd make two different apps. One running the database, receiving queries, and sending data to the other app, (on another device) querying the database. My problem is I can't find anything that could help me send simple SQL or JSON queries over wifi in an electron app.
If someone could just point me in the right direction or if someone has done this sort of thing before that would be great.
Hey #coolWinter you would need a database driver in nodejs , using this driver package you may use it's expose method and query database and process the ResultSet.
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword",
database: "mydb"
});
con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM customers", function (err, result, fields) {
if (err) throw err;
console.log(result);
});
});
Electron is basically a nodeJs using Chrome V8 Engine wrapped for desktop application - so there should not be any problem using any driver in electron application
https://www.npmjs.com/package/mysql

Node.JS MySql Module - Cannot Connect to Any Database - ECONNRESET

I'm trying to use the mysql module to connect to my database. But everytime, I get the following error: read eCONNRESET There is problem. (Note, that last part is from my console log. See below.)
I don't think this is a problem with database security settings. I've been trying to connect to my new database (hosted on AWS) for the last several days with no luck. Then, just now I attempted to connect to an Azure database that has been running smoothly for a couple years. Same problem: read eCONNRESET.
By the way, if I randomly change the host string to something invalid, my code returns an error saying the host wasn't found. So that tells me it's working to some extent.
I'm very new to the coding world and need all the help I can get.
Here's my code:
console.log('starting Launch');
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '....windows.net',
user : 'test',
password : 'test',
port : '1433'
})
console.log('step2')
connection.connect(function (err) {
if (!err)
console.log("conncetd");
else
console.log(err + "There is problem");
});
Copy full error message.
Check connectivity to your DB instance, use nmap (linux) or telnet (windows). If you can't reach host - check your local machine and server firewall, restrictions. If you can, go to 2.
Try to use different MySQL client, MySQL WorkBench, HeidiSQL, DBeaver.
If you can't - than something wrong with MySQL configuration. If you can, go to 3.
Copy info about: OS, node version, mysql module version.
you could try
mysql.createPool({});
instead of
mysql.createConnection({})

Can Nodejs retrieve data from Meteor mini mongo?

I'm trying to use Nodejs to get data from Meteorjs mini mongo database. Here is my code:
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://127.0.0.1:3001/meteor', function(err, db) {
if(err) throw err;
console.log("Connected to Database");
var test = db.collection("apps");
test.insert({"_id":"selfDefinedID"}, function(err,docs){
console.log("docs inserted");
console.log(docs);
});
test.find({"_id":"selfDefinedID"}).toArray(function(err,docs){
console.log("docs founded");
console.log(docs);
});
});
Insert data works fine. But, I can't retrieve data from meteor mini mongo database. And I got an error:
{ [MongoError: Connection Closed By Application] name: 'MongoError' }
Is it possible to retrieve Meteor mini mongo data using Nodejs? If possible, how?
The database meteor uses is a normal mongo database. You can connect to it like any other mongo db. If you are still in development mode, then the database runs at mongodb://localhost:3001/meteor, otherwise, in a bundled app, it's just the db you specified yourself using MONGO_URL.
On a windows machine, I created a new, blank, meteor project, and started it up. I then created a test script, npm installed the mongodb library, and ran your script and it worked fine. First run I get "docs inserted" and "docs founded", on subsequent runs obviously the insert is failing, but the find still works.
So two questions, first is this the same script your getting the error with? And two, if you create a blank meteor project and try it do you get the same error?

Meteor.js + external Mongo. Meteor cannot login into Mongo

I have a meteor.js app + mongo db (2.6).
I've created a user in mongo like this:
use meteor
db.createUser(
{
user: "meteor",
pwd: "password",
roles:
[
{
role: "userAdmin",
db: "meteor"
}
]
}
)
here is my mongodb.conf:
dbpath=/data/db
logpath=/var/log/mongodb/mongodb.log
logappend=true
port = 27017
when i set auth = true then my meteor app cannot connect to mongo anymore. It says
Exception in callback of async function: MongoError: auth failed
Same error when i try to connect with RoboMongo when auth is true. When auth is false i can connect with RoboMongo. So it's not about Firewall or something.
I don't understand, what I can do to switch on authorization in Mongo, so that it would let me login. Please help.
It depends on how you start Meteor. You need to tell it which Mongo instance to use and also provide proper credentials like this:
export MONGO_URL=mongodb://<username>:<password>#<host>:<port>/<db>
That's the way I've been doing it with my Meteor apps and a dedicated MongoDB and it works nicely. But if RoboMongo is not able to connect, there may be something wrong with the Mongo configuration. You can use this command to enable authentication in your config:
mongod --auth --config /path/to/mongodb.conf
I assume you have an admin user already which was used to create the meteor user, you will run into issues if you start Mongo without authentication, then add a meteor user anonymously and restart with auth=true.

Categories

Resources