Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java API for MongoDB

Tags:

java

mongodb

What is in your experience a good Java API for MongoDB?

I am searching for something with annotation based mapping of Java POJOs to MongoDB resources and a decent query abstraction layer.

like image 897
Timo Westkämper Avatar asked Sep 03 '10 12:09

Timo Westkämper


People also ask

Can I use Java with MongoDB?

Before you start using MongoDB in your Java programs, you need to make sure that you have MongoDB CLIENT and Java set up on the machine. You can check Java tutorial for Java installation on your machine. Now, let us check how to set up MongoDB CLIENT. You need to download the jar mongodb-driver-3.11.

Can you use JDBC for MongoDB?

Using the MongoDB JDBC connectivity, it's easier to place a query with the database, introduce updates to the database, and call upon stored processes.

Is MongoDB an API?

MongoDB provides APIs and drivers for a dozen programming languages, along with extensive documentation.

What is BasicDBObject in Java?

public BasicDBObject(String key, Object value) Creates an object with the given key/value. Parameters: key - key under which to store value - value to store.


2 Answers

Try Morphia http://code.google.com/p/morphia/

It works really well (haven't encountered any problems with it), eventhough it's still pre-1.0.

like image 71
bluedevil2k Avatar answered Oct 06 '22 22:10

bluedevil2k


The Spring data framework might be an alternative

http://static.springsource.org/spring-data/data-document/docs/current/reference/html/#mongo.core

Objects look like this

@Document
public class Person {

  @Id
  private ObjectId id;

  @Indexed
  private Integer ssn;

  private String firstName;

  @Indexed
  private String lastName;

}

Querying can be done via automagical Repository interfaces, or with mongoTemplate which looks like this:

List<Person> result = mongoTemplate.find(query(where("age").lt(50).and("accounts.balance").gt(1000.00d)), Person.class);
like image 44
rompetroll Avatar answered Oct 07 '22 00:10

rompetroll