wood burning stoves 2.0*
The moose likes MongoDB and the fly likes Connection to a MongoDB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » MongoDB
Bookmark "Connection to a MongoDB" Watch "Connection to a MongoDB" New topic
Author

Connection to a MongoDB

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

Guys,

Is the Connection object to a MongoDB comparable to the java sql Connection object? Do I have to open a Connection every time to the MongoDB? Does the connection pooling makes sense to a MongoDB Connection?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Joe Harry wrote:Guys,

Is the Connection object to a MongoDB comparable to the java sql Connection object? Do I have to open a Connection every time to the MongoDB? Does the connection pooling makes sense to a MongoDB Connection?

I dont think MongoDB api confirms to the JDBC API, so they have their own set of Connection, database objects. You must check the MongoDB driver documentation for more details.


Mohamed Sanaulla | My Blog
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

I have a scenario where I have a couple of domain objects which are nothing more than a POJO and are a good candidates for mapping. The project mostly uses JPA. I would like to now change all that to use mongoDB. Luckily I mapped these POJO's using XML mapping files and stayed away from annotations. I would like to do the same with mongoDB. But I checked the Spring data support for mongoDB and unfortunately I have to use annotations which breaks my portability. Is there any other way? I checked the MJORM but unsure if that is production ready.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

I had tried once to use MJORM and it was very buggy, I couldnt get around using it. I then tried Morphia which is much better, but it uses Annotation. Even if you have used the XML based mapping you might have to update those XMLs to support the ORM library you would use, which I see is same as changing the annotations in the POJO.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9345
    
    2

No. I do not have to. That old stuff exists as a separate project and it belongs to the DAO layer. The service layer that sits on top of that has one common interface and this interface will be implemented by the JPA project and now MongoDB project.

So with the JPA project in place, I have all my domain objects as POJO's in a seperate common project such that I can use them as DTO's as well apart from Entities. So I configured the mapping for those domain objects in an XML file. I would now want to have the same set up applied. That was why I was more inclined towards XML mapping. I hope Morphia in the future supports XML mapping.

Another question is, I have a method which fetches a set of data (say Question) based on the question id. I'm wondering how would I get this using the ObjectId provided by MongoDB. The problem is that this question contains many Answer objects. I have to have the possibility to fetch the answers for a Question. I would use relations to relate Question and Answer. This would mean that I would embed the questionId for all it's answers. How can I do this with the ObjectId? Any suggestions?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connection to a MongoDB
 
Similar Threads
Is MongoDB easy to install?
connection
question about EJB Transaction and connection pool?
MongoDB and NoSQL - when to use or not use it?
How to give in the context .xml for a MongoDb?..