Mongo 模板:动态修改匹配操作
Mongo Template : Modifying Match Operation dynamically
我在 mongo 模板中定义了匹配操作,如下所示。
MatchOperation match = Aggregation.match(new Criteria("workflow_stage_current_assignee").ne(null)
.andOperator(new Criteria("CreatedDate").gte(new Date(fromDate.getTimeInMillis()))
.andOperator(new Criteria("CreatedDate").lte(new Date(toDate.getTimeInMillis())))));
在此之前一切都很好。但是,我无法使用我创建的引用 match
修改此匹配操作。我一直在寻找列表类型的功能,在其中我可以在需要时将多个条件子句添加到已创建的引用中。线上的东西 match.add(new Criteria)
但是 MatchOperation
目前不支持任何可以提供此功能的方法。在这方面的任何帮助将不胜感激。
Criteria
是您添加新标准的地方,由列表支持。
使用静态 Criteria where(String key)
方法创建初始化标准对象。
类似
Criteria criteria = where("key1").is("value1");
添加更多条件
criteria.and("key2").is("value2");
创建隐式 $and
标准并链接到现有标准链。
criteria.and(where("key3).gt(value3).lte(value4))
完成后,将其传递给匹配操作即可。
MatchOperation match = Aggregation.match(criteria);
我在 mongo 模板中定义了匹配操作,如下所示。
MatchOperation match = Aggregation.match(new Criteria("workflow_stage_current_assignee").ne(null)
.andOperator(new Criteria("CreatedDate").gte(new Date(fromDate.getTimeInMillis()))
.andOperator(new Criteria("CreatedDate").lte(new Date(toDate.getTimeInMillis())))));
在此之前一切都很好。但是,我无法使用我创建的引用 match
修改此匹配操作。我一直在寻找列表类型的功能,在其中我可以在需要时将多个条件子句添加到已创建的引用中。线上的东西 match.add(new Criteria)
但是 MatchOperation
目前不支持任何可以提供此功能的方法。在这方面的任何帮助将不胜感激。
Criteria
是您添加新标准的地方,由列表支持。
使用静态 Criteria where(String key)
方法创建初始化标准对象。
类似
Criteria criteria = where("key1").is("value1");
添加更多条件
criteria.and("key2").is("value2");
创建隐式 $and
标准并链接到现有标准链。
criteria.and(where("key3).gt(value3).lte(value4))
完成后,将其传递给匹配操作即可。
MatchOperation match = Aggregation.match(criteria);