public class Foo implements IdObject {
public String id;
public String firstName;
private String lastName;
@Override
String getId() {
return id;
}
@Override
public void toDocument(Document doc) {
doc.append("id", id);
doc.append("firstName", firstName);
doc.append("lastName", lastName);
}
@Override
public String getName() {
return "foo";
}
}
MongoDB.init("",0,"","");
MongoDB db = MongoDB.getInstance();
Foo foo = new Foo();
foo.setId("1");
foo.setFirstName("zhang");
foo.setLastName("San");
db.insert(foo);
原文:http://my.oschina.net/u/612750/blog/504007