Jeg skrev en simpel repro, men havde ingen problemer med at køre den.
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();
}
}
Hvilket resulterede i dette:
{ "_id" : 1.0 , "words" : [ "a" , "b" , "c"] , "score" : 1.1 , "data" : "foo"}
...
1.0
Hvilket virker som det rigtige. Kan du køre denne kode, men erstatte din db/bruger/adgangskode?