Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access MongoDB from Java [closed]

Tags:

java

mongodb

I'm trying out MongoDB, and I wondering what the best way of mapping data from MongoDB to Java is.

My use case is that I'm trying to store 100.000+ documents (say movie+actors information), and I want to store text and image data (small images, around 100kb-300kb)

  • I've tried Morphia, but it seems to be quite dead.
  • There is a fork of Morphia, but I cannot find any experiences with that
  • I can do any data mapping by hand, but it seems like a lot of work, and I'm 'afraid' that I'll end up with something like Morphia again to make it easier for myself
  • I now there's also Spring Data for MongoDB, but I haven't checked it out yet.

What is the best way to go forward? I have the following questions:

  • Should I choose an ORM, or should I do the mapping myself? Movies seems to be quite structured, so I don't see why not to use an ORM.
  • If I go for ORM, what are the benefits of choosing Spring Data over Morphia (besides that there seems to be no releases for Morphia in the last months), or are there any solutions I haven't thought of?
  • And with the risk of asking a too broad question again: are there any other things I have to consider when storing/retrieving data? For example, should I make a collection for Movie and one for Actor, considering I want to search for both? Or should I combine the Actor and Movie relations into one document?
like image 572
Erik Pragt Avatar asked Sep 22 '26 03:09

Erik Pragt


1 Answers

Try SpringData MongoDB - it's by far the easiest way to map POJOs to documents. Could you give me a little info on your setup (IDE, build tools, etc) and I can point you to an example?

I just threw together a simple example and posted it here on GitHub. Take a look

like image 99
David Welch Avatar answered Sep 24 '26 19:09

David Welch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!