小编Chi*_*Dov的帖子

@IfProfileValue不能使用JUnit 5 SpringExtension

我使用junit5和spring-starter-test,为了运行spring test我需要使用@ExtendWith而不是@RunWith.但是,@IfProfileValue使用@RunWith(SpringRunner.class)但不使用@ExtendWith(SpringExtension.class),下面是我的代码:

@SpringBootTest
@ExtendWith({SpringExtension.class})
class MyApplicationTests{

    @Test
    @DisplayName("Application Context should be loaded")
    @IfProfileValue(name = "test-groups" , value="unit-test")
    void contextLoads() {
    }
}
Run Code Online (Sandbox Code Playgroud)

所以contextLoads应该被忽略,因为它没有指定env test-grooups.但测试只是运行而忽略了@IfProfileValue.

junit spring-test spring-profiles spring-boot junit5

6
推荐指数
1
解决办法
759
查看次数

MongoDB聚合项目返回_id数组

如我们所知,如果我们想获得一个 _id 数组,我们可以这样做:

db.collections.distinct("_id");
Run Code Online (Sandbox Code Playgroud)

我的问题是如果我需要用聚合来做一个复杂的逻辑,我怎么能得到一个 _id 数组。前任:

db.getCollection('users').aggregate({
        $match : {
            is_register_completed : { $ne : true}
        }
    }
    //other operator like $lookup, $group
    ,
     {
         $project : {_id:1}
    }
     )
Run Code Online (Sandbox Code Playgroud)

我得到

{
"_id" : "1",
"_id" : "2"
}
Run Code Online (Sandbox Code Playgroud)

我想要的就像我们做的不同

{[1,2]}
Run Code Online (Sandbox Code Playgroud)

更新: 这就是我尝试用 $group 做的事情

db.getCollection('users').aggregate({
        $match : {
            is_register_completed : { $ne : true}
        }
    },
    {
        $group: {
        _id:null, all:{$addToSet: "$_id"}
        }
     }, {$project: {_id:0,all:1}}
     )
Run Code Online (Sandbox Code Playgroud)

但我仍然得到

{
all : ["1","2"]
}
Run Code Online (Sandbox Code Playgroud)

或者我可以.map(function(el) { return el._id …

aggregate mongodb

3
推荐指数
1
解决办法
7554
查看次数