记录一下Junit测试MongoDB,获取MongoTemplate

只是自己记录一下,测试MongoDB帮助类时,没有配置文件的测试

public class HelperTest {
    
    MongoTemplate template;
    
    @Before
    public void init() {
        MongoDbFactory facotry = new SimpleMongoDbFactory(new MongoClient("127.1.1.1", 27017), "test");
        template = new MongoTemplate(facotry);
    }
    
    @Test
    public void test() {
        AggregationProxyResults<Document> results = MongodbQueryHelper.queryHotel("test", 1, template, Document.class, 
                LocalDateTime.of(2018, 04, 11, 00, 00), LocalDateTime.of(2018, 04, 12, 00, 00));
        System.out.println(results.list());
    }
AggregationProxyResults是自己封装的对查询结果的处理
原文地址:https://www.cnblogs.com/Cassie-wang/p/10142841.html