Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection to a MongoDB

 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Harry
Ranch Hand
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10122
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic