is there a way to connect mongodb with phoenix framework 1.4 version - mongodb

i am trying to use mongodb in my phoenix application. however the official documentation refers to only RDBMS (postgresql). is there a way to connect to mongodb with phoenix framework 1.4.
i am trying to build an application in phoenix which will have unstructured data. i see from the documentation of ECTO mongodb for old version. for 1.4 version of the phoenix, there is no option specified.

There does not appear to be a MongoDB/Ecto integration that is up to date with Ecto 3 yet.
But Phoenix is not your application, it is an interface. It provides the web interface. You can have other things in your application apart from Phoenix, and you can wrap MongoDB in a way that your Phoenix-based-interface can consume the data.
So the answer to your question is yes there is a way to connect MongoDB with Phoenix 1.4 but it is not plug-and-play.
Edit: I threw (emphasis on threw) together an example which can be found here
Basically it involves two applications: one a stock elixir application that is just mongodb 0.4.7 and wraps some functions. The other is a phoenix app that uses the aforementioned mongodb wrapper app. The Phoenix App needs to be created with mix phx.new --no-ecto, ostensibly you could do this as one app, but this gives you a bit more leeway.

Using the MongoDB in Phoenix is very simple. You don't need to use the Ecto stuff, because it is designed for relational database like PostgreSQL. You talk directly to the mongodb driver:
You can put the connection url into the config environment (config.ex, for example) of your Phoenix app:
config :app, :mongodb,
url: "mongodb://localhost:27017,localhost:27018,localhost:27019/my_database?replicaSet=my_replica_set"
The URL specifies a replica set of three nodes.
In application.ex you add a worker like this:
old style:
worker(Mongo, [[name: :mongo, url: Application.get_env(:app, :mongodb)[:url], timeout: 60_000, pool_size: 10]])
need style:
{Mongo, [name: :mongo, url: Application.get_env(:app, :mongodb)[:url], timeout: 60_000, pool_size: 10]}
The worker starts the GenServer with a timeout of 60 seconds and a pool size of 10 connection. After that you can use the MongoDB as usually:
Mongo.find(:mongo, "accounts", %{"email" => the_email})

Related

Quarkus 2.0 mongodb with devServices option

I have quarkus2.0 application running with mongodb database.
To run my tests, I am depending on devServices option if I am not configuring quarkus.mongodb.connection-string for test profile Quarkus will start mongod docker container for tests.
Issue I have how to pass mongodb connection string options (ex: uuidRepresentation=standard). I am using uuidRepresentation=standard option for application.
Connection-String format as per below:
mongodb://username:password#localhost:27017/dbname?authSource=admin&uuidRepresentation=standard
Have you tried the property 'quarkus.mongodb.devservices.properties' ?
I did not try it but sound like the way to go for your use case. It's avaiable on the 2.1.0 (at least, did not check with 2.0)
Yaml configuration example:
"%dev":
quarkus:
mongodb:
devservices:
properties:
uuidRepresentation: standard

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

Error trying to load driver for generic database configuration in Mule

I am using Mule 3.6 and would like to use the bulk insert option on the Generic Database Configuration to load data into mongodb 3.0.8.
I have entered the URL as:
jdbc:mongo://localhost:27017/test
and have tried a number of different Mongo and JDBC drivers but keep receiving the message "Test connection failed. Error trying to load driver..."
How can I configure the Generic Database Connector in Mule to connect to Mongo?
As already stated in this post, there is no official JDBC driver for MongoDB but one the suggested alternatives is using UnityJDBC.
If you decide to follow the UnityJDBC approach, then:
Download and install the driver by executing the following command:
java -jar UnityJDBC_Trial_Install.jar
Go to the installation folder and copy mongodb_unityjdbc_full.jar to the classpath of your Mule app.
Configure the URL and Driver in the Global Element of your Generic Database component (the values you provided are OK):
URL: jdbc:mongo://<host>:<port>/<database>
Driver Class Name: mongodb.jdbc.MongoDriver
If not, use the MongoDB Connector as suggested by #JoostD.
You need to use the MongoDB connector, it should be included in studio.
Otherwise install it from the Anypoint Exchange:
https://www.mulesoft.com/exchange/#!/mongodb-integration-connector
Also see some example on it:
https://www.mulesoft.com/exchange/#!/importing-csv-into-mongodb

Connect Gremlin shell to Titan Elasticsearch/Cassandra embedded instance?

I'm using Titan 0.3.2 in embedded mode with Cassandra and Elasticsearch. I am using the configuration documented in the titan docs for my cassandra-es.properties (fed into titan.sh/titan.bat):
storage.backend=embeddedcassandra
storage.cassandra-config-dir=config/cassandra.yaml
storage.index.search.backend=elasticsearch
storage.index.search.directory=/tmp/searchindex
storage.index.search.client-only=false
storage.index.search.local-mode=true
But I'm trying to get the right configuration for bin/cassandra-es.local to connect to the Titan server via the Gremlin client shell (with g = TitanFactory.open("cassandra-es.local") ). If I try to use the default version included with the download:
storage.backend=cassandrathrift
storage.hostname=127.0.0.1
The graph won't know anything about the ES index ("Index is unknown or not configured: search").
If I configure it with:
storage.backend=cassandrathrift
storage.hostname=127.0.0.1
storage.index.search.backend=elasticsearch
storage.index.search.client-only=false
storage.index.search.directory=/tmp/cassandra/elasticsearch
It will create an ES instance on another port that seems to exist separately from the one used by the server.
My question: (how) can I set up my Gremlin console to properly communicate with the Titan Embedded Server?
There was some recent discussion about this on the Google group. It looks like it's actually not possible to run two ES instances on one machine, so one of the easier ways around this is to set up ES separately on a VM.
I tried out this solution, and it works fine with these lines in both cassandra-es.local and titan-server-cassandra-es.properties:
storage.index.search.backend=elasticsearch
storage.index.search.hostname=<VM ES server IP>
storage.index.search.client-only=true
I can now access the same ES index from both the Gremlin shell and the Titan server.

Binding to MongoDB service from Grails application deployed on Cloudfoundry

I'm currently writing a Grails app using Grails 2.2.2 and MySQL, and have been deploying it to Cloudfoundry.
Until recently I've just used a single MySQL datasource for my domain, which Cloudfoundry detects and automagically creates and binds a MySQL service instance to.
I now have a requirement to store potentially large files somewhere, so I figured I'd take a look at MongoDB's GridFS. Cloudfoundry supports MongoDB, so I'd assumed Cloudfoundry would do some more magic when I deployed my app and would provide me with a MongoDB datasource as well.
Unfortunately I'm not prompted to create/bind a MongoDB service when I deploy my app, and I think this may be down to the way I'm connecting to Mongo.
I'm not using the MongoDB plugin, as this conflicts with another plugin I'm using, and in any case I don't need to persist any of my domain to Mongo - just some large files - so I'm using the Mongo java driver directly (similar to this - http://jameswilliams.be/blog/entry/171).
I'm unsure how Cloudfoundry detects that your application requires a particular datasource, but I'd assumed it would figure this out somehow from DataSource.groovy.
Mine looks like this...
environments {
development {
dataSource {
driverClassName = "com.mysql.jdbc.Driver"
dbCreate = "create-drop"
...
}
dataSourceMongo {
host = "localhost"
port = 27017
dbName = "my_mongo_database_name"
...
}
}
}
Is there something I'm missing? Or do I need to manually bind the MongoDB service somehow?
Using answer instead of comments for better formatting. :)
I guess you have already followed step to create the MongoDB service in Cloudfoundry as mentioned here otherwise this has to be done. Plus, it will be lot easier if you use the Groovy wrapper of the Java Driver of MongoDB called GMongo. Refer the GitHUb Source and this Mongo blog for more details.