Question

I am a new to using Mongo DB and exploring the frameworks around for migrating from mysql to mongodb. So far from my findings I have been able to figure out SpringMongo as the best solution to my requirements.

The only problem is that instead of using a DSL based or abstract querying mechanism, I wished the framework allowed me to pass plain json string as arguments to the different methods exposed by the API(find, findOne) so that the query parameters can be written out to an external file (using a key to refer) and passed to the methods by reading and parsing at run time. But the framework should be capable of mapping the results to the domain objects.

Is there a way in spring-mongo to achieve this? Or is there any other frameworks on the same lines

Was it helpful?

Solution

You could use Spring Data to do that, just use the BasicQuery class instead of Query class. Your code will look like the following:

/* Any arbitrary string that could to parsed to DBObject */
Query q = new BasicQuery("{ filter : true }");
List<Entity> entities = this.template.find(q, Entity.class);

If you want more details:

http://static.springsource.org/spring-data/data-mongo/docs/current/reference/html/#mongo.query

http://static.springsource.org/spring-data/data-mongodb/docs/current/api/org/springframework/data/mongodb/core/query/BasicQuery.html

OTHER TIPS

Well I got to find this one in the Spring data MongoOperations...

String jsonCommand = "{username: 'mickey'}";
MongoOperations mongoOps = //get mongooperations implemantation
mongoOps.executeCommand(jsonCommand)

It returns an instance of CommandResult that encapsulates the result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top