There is a Windows Forms application, which uses MongoDB driver.
I would like the MongoDB driver to make all its connection via a specified proxy.
Should there be a way to modify app.config to achieve it?
Can I define it in the driver itself?
Take a look at the MongoDB docs on connection strings: http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial#CSharpDriverTutorial-Connectionstrings
How your particular application stores this connection string isn't defined by MongoDB. It doesn't use app.config unless your code uses it.
Related
I am a Rust newbie and am trying to create a REST API using actix and mongodb.
Before starting up the I am trying to connect to a local MongoDB instance Using the official rust client from here. Here is the code I am trying
let client = Client::with_uri_str("mongodb://localhost:27017").expect("Error getting client");
let database = client.database("mydb");
let collection = database.collection("books");
Rustc version is 1.44 and MongoDB driver version 1.0.0
While running this code, I do not get an error if the local mongodb server is not running.
How do we figure out if the connection to the DB has been successful or not ? No point continuing if the DB connection itself is not established.
The drivers are required to establish connections in the background. Instantiating a client is supposed to always succeed.
The purpose of this is to, for example, allow the application and the database to be started at the same time - when the database becomes available, the application will be able to use it.
To find out whether your database is operational, execute a command such as ping. Most applications will simply carry on with their normal queries/updates.
I want to connect to Mongo DB from Apama and store the events there in JSON document format. Is there any way to establish the connectivity either using JDBC or Java API invocation?
There is currently (up to Apama 10.3.1) no built-in connectivity for MongoDB.
However, I expect you should be able to use one of our standard public extension API's to add such an extension. Most likely would be to use the Correlator "Connectivity Plugin" API with a 3rd-party client library in either C++ or Java.
Kev
While using relational databases like MySQL, we can create a JNDI resource in GlassFish server(which I am using) and then use it as DataSource by looking up the context.
Is there an equivalent way for doing this for MongoDB in GlassFish?
If no then what is the best way to store the connection details like DB username and password for MongoDB without hard-coding them into the application or having some kind of properties files inside the web application from where we access the connections details?
I am using a Java Servlet as my web technology.
You can define an alias in glassfish for your password and access it by calling System.getProperty("mypassword")
I am developing a Jee7 project and would like to employ mongoDB as the backend database.
My jee7 application will run on Glassfish 4.
I wish to use the Glassfish 4 admin console to configure my mongoDB jdbc connection pool etc..
However Glassfish 4 doesn't list mongoDB in its list of supported Database Driver Vendor
Does this mean that you do not configure mongoDB in the same way as say DB2 or MySQL?
I could configure mongoDB using a EJB singleton, but that doesn't feel correct.
I don't think you can without writing your own resource adapter. First, mongodb is non-transactionable, so it's not like it needs to participate in any transaction related events. Second, their java driver manages the connection with their own internal connection pool.
Although it would be nice to configure the resource outside of the app, in reality you should just create a singleton bean and do everything from there.
Also take a look at producers.
I'm using the datanucleus mongodb maven plugin and "access platform" for connecting my java app to mongodb using JPA.
I've followed the instructions on http://docs.mongodb.org/manual/tutorial/deploy-replica-set/
on a ubuntu VM, added db1.mongo, db2.mongo and db3.mongo into the hosts file on both the guest vm and the host (Mac OS X).
I got a simple java app connecting to the servers, (as described in http://www.datanucleus.org/products/accessplatform_3_0/mongodb/support.html).
When I connect the app to the primary (connection url: mongodb:db1.mongo:27017/ops?replicaSet=rs0) everything works just fine, but when I add the other two mongodb's to the connection url, so it becomes mongodb:db1.mongo:27017/ops?replicaSet=rs0,db2.mongo:27018,db3.mongo:27019 I get the exception:
com.mongodb.MongoException: can't find a master
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:503)
at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:236)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216)
...
I've searched for this error, but the ones I have found concerns use of localhost/127.0.0.1. I tried to mitigate that by running mongodb on a separate VM and thus a non-local IP as well as adding the names to the hosts file.
The primary goal with trying mongodb is to achieve availability so replication and being able to failover is extremely important. Transactions and consistency between nodes in case of failure is not a problem, neither are we concerned about loosing an update or two once in a while so mongodb looks like a good alternative using JPA (I'm utterly fed up with mysql :-)
Thanks in advance for your help!
I used multiple MongoDB servers when I originally wrote that support and worked back then. Not got time now, but you can look at the DataNucleus code that parses your datastore connection URL and converts it into MongoDB java API calls. Should strip the servers apart and then call "new Mongo(serverAddrs);". If its passing it in correctly (debugger?), then the problem is possibly Mongo-specific, as opposed to what DataNucleus does for you.
Also make sure you're using v3.1.2 (or later) of datanucleus-mongodb
I think you've misformatted your MongoDB URI. Instead of this:
mongodb:db1.mongo:27017/ops?replicaSet=rs0,db2.mongo:27018,db3.mongo:27019
Do this:
mongodb:db1.mongo:27017,db2.mongo:27018,db3.mongo:27019/ops?replicaSet=rs0