[英]Query is working in Mongo but not working with spring-data-mongo
I have a collection in mongo which contains 6 documents .When I run query directly in mongo it is qorking fine.But when I run the same query in spring , I am not getting the result 我在mongo中有一个包含6个文档的集合。当我直接在mongo中运行查询时很好,但是当我在春季运行相同的查询时,我没有得到结果
I have the following query 我有以下查询
Mongo DB: db.getCollection('table_name').find({"column_1" : "value_1" })
Spring : 春季:
Query q = new BasicQuery("{ column_1: 'value_1'}");
this.mongoOps.find(q, TableName.class, "table_name");
I tried with different mongo versions ans with different spring versions but not working.What might be the issue here. 我尝试了不同的mongo版本和不同的spring版本,但是没有用。这里可能是问题所在。
NOTE:Query is working with JDBC as well 注意:查询也与JDBC一起使用
Thanks in advance... 提前致谢...
If you're considerating use Query
class, try add Criteria
如果您考虑使用Query
类,请尝试添加Criteria
Query query = new Query();
query.addCriteria(Criteria.where("field_1").in("value_1"));
Edit If you want to use BasicQuery
, try: 编辑如果要使用BasicQuery
,请尝试:
BasicQuery query1 = new BasicQuery("{ 'field': 'value_1' }");
User userTest1 = mongoOperation.findOne(query1, YourClass.class);
Remember in Mongo we don't call column to fields, because it doesn't has column :) 请记住,在Mongo中,我们不将column称为字段,因为它没有column :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.