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.
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.
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.
MongoDB provides APIs and drivers for a dozen programming languages, along with extensive documentation.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With