当前位置: 代码迷 >> 综合 >> mongo find()后加一个first()是什么意思?
  详细解决方案

mongo find()后加一个first()是什么意思?

热度:37   发布时间:2023-09-21 17:47:25.0

mongo2中只有find,findOne是mongo3中才有的,所以旧的写法想达到和findOne一样的效果,就需要在find后在加first()

 

In MongoDB 2 Java driver there was a method on the DBCollection class named findOne().

In the MongoDB 3 Java driver API, the findOne() method isn't there. So your new code for finding exactly one document becomes similar too this one:

collection.find(eq("_id", 3)).first()
  相关解决方案