Saya menulis repro sederhana tetapi tidak ada masalah saat menjalankannya dengan sukses.
public static void main(String[] args) throws UnknownHostException, MongoException {
Mongo mongo = new Mongo();
DB db = mongo.getDB("test");
boolean auth = db.authenticate("scott", "scott".toCharArray());
DBCollection coll = db.getCollection("myWords");
DBObject dbObj = (DBObject) JSON.parse("{ \"_id\" : 1.0 , \"words\" : [ \"a\" , \"b\" , \"c\"] , \"score\" : 1.1 , \"data\" : \"foo\"}");
coll.insert(dbObj);
System.out.print(coll.findOne().toString());
Morphia morphia = new Morphia();
Datastore datastore = morphia.createDatastore(mongo, "test");
Word w = datastore.find(Word.class).get();
System.out.print(w);
}
@Entity("myWords")
static class Word {
@Id Double id;
ArrayList<String> words = new ArrayList<String>();
Double score;
String data;
@Override
public String toString() {
return this.id.toString();
}
}
Yang mengakibatkan ini:
{ "_id" : 1.0 , "words" : [ "a" , "b" , "c"] , "score" : 1.1 , "data" : "foo"}
...
1.0
Yang sepertinya hal yang benar. Bisakah Anda menjalankan kode ini, tetapi ganti db/user/password Anda?