Scala Lift - Connect to remote MongoDB - scala

I currently have my app running on my local machine, in Boot.scala I have:
MongoDB.defineDb(
DefaultMongoIdentifier,
MongoAddress(MongoHost("127.0.0.1", 27017), "platform")
)
I've successfully deployed the app to a cloud provider, and am in the process of setting up a database # mongohq.com
What would I need to change to enable the app to connect? I've taken a look here:
https://www.assembla.com/wiki/show/liftweb/Mongo_Configuration
But am a little confused by the connection details provided by mongohq, all they provide is:
Mongo URI
mongodb://<user>:<password>#<host>:<port>/<my_account_name>
Thanks in advance for any help, much appreciated :)

I am not familiar with MongoHQ in particular, but you should be able to put something in Boot like this:
MongoDB.defineDbAuth(
DefaultMongoIdentifier,
new Mongo(new ServerAddress("<host>", <port>)),
<my_account_name>,
<user>,
<pass>
)
Where the <*> variables are the particular part of the connection URI that were provided to you when you signed up for MongoHQ.

Related

Connecting Postgres instance to AppEngine - Google Cloud, with SpringBoot

I've nearly got a SpringBoot app running on Google Cloud services that is connected to a Postgres instance.
I've ran through the steps on their guide, located here and have gotten to the point where I need to set my variables up for the app to find the database instance:
The problem encountered is two fold:
I don't know where and how to set these
My server logs report this error:
meaning that the Spring application is trying to find the database like it would on my local.
I set the following values in the app.yaml (assuming this is where they should be?)
runtime: java11
instance_class: F1
env_variables:
SQL_USER: quickstart-user
SQL_PASSWORD: <password>
SQL_DATABASE: quickstart_db
INSTANCE_CONNECTION_NAME: quickstart-instance
So, my question(s) are:
Is this the correct place to set them?
If not, do I need a appengine-web.xml file instead (And does anyone have an example of what this looks like, I can't find one)
How do I stop the app from looking for the local database?
Thanks

How do i deploy a Perfect (swift) backend code + PostgreSQL to Google App Engine

i'm pretty new to web development and much more in Google Cloud, sorry for anything.
Basically, i'm doing the backend part of an app in Swift (using Perfect), and it's running smoothly and okay in my local computer, i'm using a local Postgre database (using PostgreORM in my application).
But, when i deploy that to the Google Cloud, it does not recognize the database (i've created a identical poster database in the computer engine AND a Cloud SQL (Postgre service of Google Cloud with the same names and credentials), but again, when the app is on the cloud, it does not recognize the database, what i'm missing? How should i do it? Install other docker image with Postgre?
Here's my DBConnector code:
import PostgresStORM
func setupDBCredentials() -> PostgresConnector.Type{
let connection = PostgresConnector.self
connection.host = "localhost" // or the connection name of the Google Cloud, it doesn't work as well
connection.username = "postgres"
connection.password = "nearby"
connection.database = "nearby"
connection.port = 5432
return connection
}
Basically, how do i make my google app engine code connect to any database at all?
Also, if it helps, i'm using the Perfect Assistant to deploy my code to Google Cloud, using Docker.
Thanks already!
You'll likely need to do a few things to get connected, such as granting access to the Cloud SQL instance. Here is the link to the PHP docs that cover the broad steps that you'll want to follow and it shows a representation of the connection string that you'll also need.
I believe your connection string needs to look something like this
pgsql:dbname=DATABASE;host=/cloudsql/CONNECTION_NAME
Where CONNECTION_NAME is in the format of PROJECT_ID:CLOUD_SQL_REGION_ID:CLOUD_SQL_INSTANCE_ID

Connect to MongoDB from Spring Boot Application over SSL

I use the following adjustments for local development in the application.properties:
myproject.mongodb.databaseName=databaseName
myproject.mongodb.databaseAddress=serverName.mycompany.at
myproject.mongodb.databasePort=27017
myproject.mongodb.username=myProjectName
myproject.mongodb.password=asdfasdf
myproject.mongodb.mappingBasePackage=domain
Now I will use the app in a productiv way and therefore need SSL like I can adjust with RoboMongo:
Does anyone know what I have to set in my application.properties file?
As far as I know the only way to connect with options (without extra code) is to use the connection string/uri. It would look something like this:
spring.data.mongodb.uri=mongodb://myProjectName:asdfasdf#serverName.mycompany.at:27017/databaseName?ssl=true

Spring REST MongoDB Starter Application queries

So I used the Spring MongoDB application starter kit from Github. I tried running the application and it ran great. All the functionality work great. I am confused how the connection for this is being established. Where does one specify the db userid, password and the db name? Coming from a MySQL background, though MongoDB isnt a mountain there are some differences that dont set clearly in the mind of newbies.
I followed the official documentation from here : https://spring.io/guides/gs/accessing-mongodb-data-rest/. Maybe can the above info be added to the docs?
You should read some docs on Springboot. Springboot is opinionated. That means it assumes lot of stuff and sets-up lot of things for you. For example, in your case, As soon as it sees mongo dependency in your pom. It will create a connection to mongodb with default values which are as follows
host: localhost
port: 27017
username:
password:
database: test
That is how it is working. But if you want it to be customized, even that is made easy by specifying in configuration files (application.properties or yaml). See the list of configuration properties that you can set
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

ElasticSearch with Play 2 configuration

I am trying to use the ElasticSearch module (https://github.com/cleverage/play2-elasticsearch) with my Play 2 application. In the readme, it says I should add the following to my application.conf:
## define local mode or not
elasticsearch.local=false
## list clients
elasticsearch.client="192.168.0.46:9300"
# ex : elasticsearch.client="192.168.0.46:9300,192.168.0.47:9300"
What is local mode? What is my client URL supposed to be? I can not find any information on what these options should be. With my current options, I get a NoNodeAvailableException.
Some people suggest:
elasticsearch.local=false elasticsearch.client=mynode1:9200,mynode2:9200
But what is mynode1 and mynode2? It doesn't work with my application. Can anyone help? Thanks
What is local mode?
If elaticsearch.local=true, a elasticsearch node is started in your application ( embedded )
What is my client URL supposed to be?
It's your host:port, but the port is the tcp transport define on your elasticsearch node.
By default, the port start on 9300 ( http://www.elasticsearch.org/guide/reference/modules/transport.html )
I can not find any information on what these options should be. With my current options, I get a NoNodeAvailableException.
I think you have a problem on port number.
mynode1 and mynode2 are elasticsearch nodes.
Do you have any Elasticsearch node running?
On which IP address?
Can you try to connect on these nodes using curl, for example:
curl localhost:9200
Or
curl YOURIPADDRESS:9200
If one of this is successful, then configure your play app using YOURIPADDRESS:9300 as Nicolas Boire wrote before.
If no one is successful, check that you have installed Elasticsearch and launched it before.
HTH
I've just had the same problem, be sure that you respect the version requirements written in the table : https://github.com/cleverage/play2-elasticsearch
At the beginning, I set up the latest version of the plugin 0.8.1 but my ElasticSearch version was 1.0.2.
By starting ES with version 0.9.13, it worked.