java - Spring Data 中 MongoOperations 中的 findOne 方法的行为是什么?

标签 java spring mongodb spring-data

我正在阅读 MongoOperations 的 SpringData MongoDB 配置 http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/MongoOperations.html#findOne-org.springframework.data.mongodb.core.query.Query-java.lang.Class-

仍然不明白如果多个文档满足查询,findOne 方法的行为是什么:

<T> T   findOne(Query query, Class<T> entityClass)

最佳答案

根据 Mongo 文档本身,findOne() 方法将根据磁盘上元素的自然顺序返回遇到的第一个元素:

Returns one document that satisfies the specified query criteria. If multiple documents satisfy the query, this method returns the first document according to the natural order which reflects the order of documents on the disk. In capped collections, natural order is the same as insertion order. If no document satisfies the query, the method returns null

http://docs.mongodb.org/master/reference/method/db.collection.findOne/

关于java - Spring Data 中 MongoOperations 中的 findOne 方法的行为是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32616800/

相关文章:

performance - javascript shell 与 pymongo 中 db.eval() 的 MongoDB 性能

java - EJB 重写 JPA javax.persistence

java - 为什么 jacoco :cover report 0 tests, 0 次失败,0 次错误用于 Play 2.2 中的测试?

java - Spring app 对非 spring webapp 的响应

java - RESTful Spring MVC 是否可以重复参数?

java - spring 为带注释的方法强制执行事务逻辑

mongodb - 原则 ODM 和无模式设计

java - 我可以将对象用作java中方法的变量吗?

java - 编程挑战扫雷帮助 : How to check for a "*" in a 2D string array?

javascript - 如何在 express.js 应用程序启动之前加载异步数据库 url 并启动数据库连接?