mardi 3 mars 2015

How can I coax Spring Data to show me mongo's query plan (a.k.a cursor.explain())

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();


And my abstract DAO looks like this:



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


What I can't tell is if the @Indexed annotation is working. I'd like to try explain, ( http://ift.tt/11uy3BJ), 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);
}


Any help you can provided will be much appreciated!


Aucun commentaire:

Enregistrer un commentaire