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.
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.
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.
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);
Used both on two different projects. Started out using Morphia but lack of support by main developer limited us. Even though 10gen hired Morphia developer, support for Morphia seemed to be wavering.
When I asked 10gen folks about their plans for Morphia I got no clear response. We switched to spring data on other project and API seems more complete and better docs and community.