我想要做一個簡單的findOne()使用嗎啡。我的代碼如下:Morphia映射與我的JAVA類
public static void main(String[] args)
{
MongoClient client = new MongoClient();
Morphia morphia = new Morphia();
morphia.map(Restaurant_M.class);
Datastore ds = morphia.createDatastore(client, "test");
System.out.println(ds.find(Restaurant_M.class).get());
client.close();
}
我得到一個null打印出來。我無法找到發生了什麼問題。有人能指引我朝着正確的方向嗎?謝謝。
編輯 採集格式
{
"_id" : ObjectId("572eb5df1d739cc73c21f953"),
"address" : {
"building" : "469",
"coord" : [
-73.961704,
40.662942
],
"street" : "Flatbush Avenue",
"zipcode" : "11225"
},
"borough" : "Brooklyn",
"cuisine" : "Hamburgers",
"grades" : [
{
"date" : ISODate("2014-12-30T00:00:00Z"),
"grade" : "A",
"score" : 8
},
{
"date" : ISODate("2014-07-01T00:00:00Z"),
"grade" : "B",
"score" : 23
},
{
"date" : ISODate("2013-04-30T00:00:00Z"),
"grade" : "A",
"score" : 12
},
{
"date" : ISODate("2012-05-08T00:00:00Z"),
"grade" : "A",
"score" : 12
}
],
"name" : "Wendy'S",
"restaurant_id" : "30112340"
}
@Entity類
@Entity("restaurants")
public class Restaurant_M
{
@Id
public ObjectId _id;
@Property("borough")
public String town;
public String cuisine;
public String name;
@Property("restaurant_id")
public String r_id;
我已經編輯附加信息的問題。我想我提供了有關該實體的完整映射信息 – Newton