我是一个使用Mongo DB和探索从mysql迁移到mongodb的框架的新手。到目前为止,根据我的发现,我已经能够将SpringMongo作为满足我的需求的最佳解决方案。
唯一的问题是,与使用基于领域特定语言的或抽象的查询机制不同,我希望框架允许我将纯json string作为参数传递给API(find,findOne)公开的不同方法,这样查询参数就可以写出到外部文件(使用键引用),并在运行时通过读取和解析传递给方法。但是框架应该能够将结果映射到域对象。
在spring-mongo中有什么方法可以做到这一点吗?或者,在同一行上还有其他框架吗?
发布于 2012-12-05 07:43:16
您可以使用Spring Data来实现这一点,只需使用BasicQuery类而不是Query类。您的代码将如下所示:
/* Any arbitrary string that could to parsed to DBObject */
Query q = new BasicQuery("{ filter : true }");
List<Entity> entities = this.template.find(q, Entity.class);如果需要更多详细信息,请执行以下操作:
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
发布于 2012-12-11 21:24:32
我在Spring data MongoOperations中找到了这个……
String jsonCommand = "{username: 'mickey'}";
MongoOperations mongoOps = //get mongooperations implemantation
mongoOps.executeCommand(jsonCommand)它返回一个封装结果的CommandResult实例。
https://stackoverflow.com/questions/13395196
复制相似问题