- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
一些其他进程将文档插入到mongo集合中,下面是示例数据
{ "_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 }
我正在尝试使用 QueryByExampleExecutor 为 clientId 获取一条记录。
这是我的模型
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 与 mongo 集合中的包不同。我如何告诉 mongo 在没有 _class 的情况下构建查询。我尝试了 withIgnoredPaths 但它不起作用。
最佳答案
MongoExampleMapper
检查探测类型并根据已知类型在 MappingContext
中写入类型限制。可分配给探测器的类型包含在 $in
运算符中。
class One {
@Id String id;
String value;
// ...
}
class Two extends One {
// ...
}
One probe = new One();
probe.value = "firefight";
Example<One> example = Example.of(probe, ExampleMatcher.matchingAny());
{
value: firefight,
_class: { $in : [ "com.example.One" , "com.example.Two" ] }
}
此行为不能通过使用 .withIgnorePaths()
来改变,因为 _class
说明符不是域模型的一部分。请在 jira.spring.io 中提出问题如果您认为应该考虑这一点。
查看提供的 mongo 集合中提供的示例数据,您提供的 _class
属性与您的域类型不匹配,因此无法加载。
关于java - Mongodb QueryByExample 查找一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45381431/
我有一个带有存储库的 Spring 应用程序 interface EventRepository extends JpaRepository, QueryByExampleExecutor { } E
一些其他进程将文档插入到mongo集合中,下面是示例数据 { "_id" : ObjectId("597b89c8da52380b04ee6948"), "_class" : "com.test.mo
我有以下 JPA 存储库: public interface PostRepository extends JpaRepository { List findAll(); List f
TLDR 有没有办法将 queryByExample 限制为 NodeJS 中的集合? 面临的问题 我有一个带有一些可选字段的复杂查询(即有时会省略一些搜索字段)。所以我需要动态创建一个查询,例如在
我正在使用 Criteria 来加速查询,而且我快完成了。 使用 Query By Example 匹配表中的行,删除具有相同 id 的重复行,然后分页。 当然,在删除重复行之前我无法分页,而且我不知
我是一名优秀的程序员,十分优秀!