我有如下课程:
@Entity("Collection_IAGlobals")
public class MoDBIAGlobals {
@Id
@Indexed
String id;
@Embedded
Map<EnumChannelType, MoDBChannel> data = new HashMap<EnumChannelType, MoDBChannel>();
}
其中,MoDBChannel 类是:
@Entity("Collection_IAGlobals")
@Embedded
public class MoDBChannel extends MoDBTopic {
@Indexed
private String channelId;
@Embedded
private Map<String, MoDBTopic> data = new HashMap<String, MoDBTopic>();
}
MoDBTopic 类是:
@Entity("Collection_IAGlobals")
@Embedded
public class MoDBTopic {
private String topic;
private Double score1 = 0.0;
private Double score2 = 0.0;
}
和 MoDBIA_DAO 类:
public class MoDBIA_DAO extends BasicDAO<MoDBIAGlobals, String> {
public MoDBIA_DAO(Mongo mongo, Morphia morphia, String dbName) {
super(mongo, morphia, dbName);
}
}
我有一个 MoDBIAGlobals 类的对象保存为:
dataStore.save(globals)
其中全局的 JSON 如下:
{"id":"usr1234",
"data":{"FACEBOOK":{"channelId":"FB1234",
"data":{"NO_TOPIC":{"topic":"NO_TOPIC",
"score1":1.0,
"score2":0.0}},
"score1":0.0,
"score2":0.0}}}
现在我想查询以获取MoDBIAGlobals
where"id"=="usr1234"
和"channelId"=="FB1234"
. 如何创建此查询?
我尝试如下,但我无法得到任何结果:
MoDBIA_DAO dao = new MoDBIA_DAO(mongo, morphia, DB_Name);
Datastore dataStore = morphia.createDatastore(mongo, DB_Name);
Query<MoDBIAGlobals> query = dataStore.createQuery(MoDBIAGlobals.class).disableValidation();
query.field("data.channelId").equal("FB1234");
query.field("data.data.topic").equal("NO_TOPIC");
QueryResults<MoDBIAGlobals> results = dao.find(query);
System.out.println("results: " + results);
System.out.println("results.count: " + results.countAll());
它的打印结果为:
results: { "data.channelId" : "FB1234" , "data.data.topic" : "NO_TOPIC"}
results.count: 0
我做错什么了吗?