Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using MongoDB in Java

 
Rahul Pandya
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I recently began working with MongoDB in java.

I am right now stuck with what to use?
I read a lot about Data persistence in Java and have narrowed it down to these options

1. Pure JDBC
2. Spring JDBC with Spring Mongodb
3. Datanucleus (and why not pure JDO)
4. Kundera JPA (Its support for MongoDB)


Case 2 : If in future if I plan to use some other NoSQL database which will benefit me greatly
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want a database-agnostic library that you can use with other NoSQL databases as well as SQL databases, then I guess Spring Data might be your best option. Not sure how many NoSQL databases are supported, and it may be more trouble than it's worth for simple applications. I'm not sure how easy it is to swap out e.g. MongoDB for Neo4J or PostgreSQL even with Spring Data's supposedly generic approach.

If you are looking specifically for Java MongoDB drivers, you could start with the official Java driver, which now includes support for asynchronous processing (good for scalability), and is fairly well documented on the MongoDB website: http://docs.mongodb.org/ecosystem/drivers/java/

If you want to find out more about how to use MongoDB with Java, you could try the free online course M101J MongoDB for Java Developers.
 
Tim Holloway
Saloon Keeper
Posts: 18362
56
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a project using Spring Data for Neo4j (also known as "SDN"). You can see it at https://github.com/mtsinc1/Dibs.

At the moment, the Neo4j interface isn't very portable, I fear, and one thing that I'm used to having when using Spring is transparent transaction support. Which, for some reason I (and others) have a lot of trouble getting to work properly in SDN at the moment, which is why the code is infested with manual transaction management.

Spring has several advantages. It provides a general Inversion of Control architecture to programs - not just database stuff, but all sorts of things. I use it to swap in and out dummy emailer modules for testing, as an example.

In the database realm, it provides good ORM support, does the grunt work that goes around database functions, such as getting and releasing connections and genericized error handling and - except as noted above - it's pretty good about transaction handling as well.

Although Spring does try to abstract things, the Neo4j approach is pretty different from traditional SQL databases, since it's predicated more on the relationships than the data. MongoDB is probably easier to swap back and forth with SQL-oriented stuff.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic