I'm working on a POC using spring boot application with mongodb, and embedded mongodb (flapdoodle) for unit tests.
I've searched for a GUI for embedded mongodb (flapdoodle), but haven't found anything about this. Is there a GUI for embedded mongodb ?
Just use any mongodb GUI tool. Start the spring boot so the mongodb instance is alive and then use the GUI tool. I was able to use Compass to connect to my embedded instance at localhost:37681. The port of course depends on your configuration.
Spring Boot logs the MongoDB port when it starts the unit test execution, I am using the URI property to connect the embedded DB and it is mongodb://localhost/test, in this case the port would change for each run. Also if you have multiple unit test classes configured with Test profile then MongoDB will be created for each class, meaning if you are inserting records from one unit test class and trying to retrieve from other unit test class would fail as the second one uses a new connection. Below is a sample logs with MongoDB port,
[INFO] - - 2020-09-02 17:47:06.782 740 --- [localhost:51767]
org.mongodb.driver.connection : -- Opened connection
[connectionId{localValue:1, serverValue:1}] to localhost:51767
Related
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
I have a play scala app and i have an atlas cluster which i am trying to connect. According to the ReactiveMongo this is possible. I can add my connection string gotten from Atlas to my app via
mongodb.uri
In my application.conf file. I have tried everything based on the instructions from reactivemongo and atlas db but i am still unable to connect to the cluster. using my mongoshell however, i am able to connect and have access to my db but it simply refuses to connect via my app.
Mongo simply returns an error "MongoError['No primary node is available! (Supervisor-13/Connection-14)']" } and logs a warning in my console Some options were ignored because they are not supported (yet): w, retryWrites. I am using scala version 2.12 and reactivemongo 0.12.6 with play 2.6.
My connection string is mongodb+srv://<username>:<password>#my-cluster.abo25.mongodb.net/my-db?retryWrites=true&w=majority
Any info or help would be greatly appreciated.
Solved my problem. It turns out the +srv string format works seamlessly from reactivemongo version 0.17 and i was initially on 0.16. After i upgraded (and also upgraded my code), i was able to connect to my cluster. I also found out one of the user credentials i was using was wrong so that plus the upgrade got me up and running.
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})
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
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.