执行简单查询时,我遇到了重复的查询。文件:
SomeClass.java:
@Document(collection = "someCollection")
public class SomeClass {
private String _id;
private String someField;
//...
}
SomeClassRepository.java:
@Repository
public interface SomeClassRepository extends MongoRepository<SomeClass, String> {
}
Service.java:
@Autowired
private SomeClassRepository someClassRepository;
public SomeClass find(String id){
return someClassRepository.findOne(id);
}
application.properties:
logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG
日志文件:
14:14:46.514 [qtp1658534033-19] DEBUG o.s.data.mongodb.core.MongoTemplate - findOne using query: { "_id" : "40c23743-afdb-45ca-9231-c467f8e8b320"} fields: null for class: class com.somepackage.SomeClass in collection: someCollection
14:14:46.534 [qtp1658534033-19] DEBUG o.s.data.mongodb.core.MongoTemplate - findOne using query: { "_id" : "40c23743-afdb-45ca-9231-c467f8e8b320"} in db.collection: someDatabase.someCollection
我也试过:
1)将@Id注释与名为“someId”的字段一起使用 2)使用名为“id”的字段的@Id注释 3)使用名为“id”的字段(不带@Id注释)
不幸的是,我总是对数据库有两个查询。
任何人都知道如何执行单个查询?
谢谢!