2
其他一些过程将文档转换为蒙戈收集和下面是样本数据MongoDB的QueryByExample findOne
{ "_id" : ObjectId("597b89c8da52380b04ee6948"), "_class" : "com.test.mongo", "clientId" : "CAQ123999", "isValid" : false, "isParent" : true }
{ "_id" : ObjectId("597b89c8da52380b04ee6949"), "_class" : "com.test.mongo", "clientId" : "CAQ123999", "isValid" : false, "isParent" : true }
{ "_id" : ObjectId("597b89c8da52380b04ee6950"), "_class" : "com.test.mongo", "clientId" : "CAQ123998", "isValid" : true, "isParent" : true }
{ "_id" : ObjectId("597b89c8da52380b04ee6951"), "_class" : "com.test.mongo", "clientId" : "CAQ123997", "isValid" : true, "isParent" : false }
我试图抓住一个记录ClientID的,使用QueryByExampleExecutor。
这里是我的模型
package com.test.cfp.model;
public class TFSModel {
private String clientId;
private boolean isValid;
private boolean isParent;
...
}
这里是构建示例代码:
TFSModel tfs = new TFSModel();
tfs.setClientId(CAQ123999);
tfs.setValid(false);
tfs.setParent(true);
ExampleMatcher matcher =ExampleMatcher.matching().withIgnoreNullValues().withIgnorePaths("_id","_class");
Example<TFSModel > example = Example.of(tfs,matcher);
TFSModel oneTfsRecord = tflsRepository.findOne(example);
这不是工作,下面是生成的查询
findOne using query: { "isValid" : false , "isParent" : true , "clientId" : "CAQ123999" , "_class" : { "$in" : [ "com.test.cfp.model.TFSModel"]}} in db.collection: returns.tfs;
很明显,_class与mong中的不同o收藏。我如何告诉mongo在没有_class的情况下构建一个查询。我尝试过使用IgororedPaths,但它不工作。
谢谢@Christoph Strobl。我结束了使用MongoTemplate。我不确定它是否有效。无论如何,我会尝试在jira.spring.io中记录此信息。 – PKR