我该如何哄骗Spring

我该如何哄骗Spring

本文介绍了我该如何哄骗Spring Data向我展示mongo的查询计划(又称cursor.explain())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用Spring/Mongo/Jersey编写一个API,以对具有如下通用属性映射的POJO进行CRUD:

I am writing an API with Spring/Mongo/Jersey to do CRUD on a POJO that has a generic map of properties like this:

public class Thing {
    private String id;

    @Indexed
    private Map<String,String> properties;
...

退货很有效.我的资源代码如下:

This is working great to return items. My resource code looks like this:

BasicDBObject query = new BasicDBObject("properties.name", "vlad the impaler");
return Response.ok(myService.queryThings(query)).build();

我的抽象DAO看起来像这样:

And my abstract DAO looks like this:

public List<T> find(Query query) {
        return mongoOps.find(query, clazzOfItem);
}

我不知道 @Indexed 注释是否有效.我想尝试解释,( http://docs.mongodb.org/manual/reference/method/cursor.explain/ ),但我看不到任何示例向我展示如何从spring数据中调用较低级别的驱动程序API.

What I can't tell is if the @Indexed annotation is working. I'd like to try explain, (http://docs.mongodb.org/manual/reference/method/cursor.explain/), but I don't see any examples that show me how to call the lower level driver API from spring data.

我希望能够像这样打开调试:

I'd like to be able to turn on debugging like so:

public List<T> find(Query query) {
        if (debugOn) {
            String queryPathDetails = mongoOps.executeCommand( /*NOW WHAT??*/ ).toString();
            logger.log(queryPathDetails);
        }
        return mongoOps.find(query, clazzOfItem);
}

我们将不胜感激!

推荐答案

我们目前还不提供支持,但是您可以简单地设置一个断点此处 org.springframework.data.mongodb.core.MongoTemplate.QueryCursorPreparer.prepare(..)

We don't provide support for that yet, but you could simply set a breakpoint here org.springframework.data.mongodb.core.MongoTemplate.QueryCursorPreparer.prepare(..)

在您选择的调试器中,您只需执行一个

In the debugger of your choice you can then simply execute a

cursor.explain()

例如通过日食显示视图.

e.g. via the eclipse display view.

这篇关于我该如何哄骗Spring Data向我展示mongo的查询计划(又称cursor.explain())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:22