• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connection to a MongoDB

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic