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()
本文探讨了从MongoDB 2.x到3.x版本中,如何将findOne方法进行迁移。在MongoDB 3.x中,findOne方法不再存在,替代方案是使用find方法结合first()来实现相同的功能。例如,可以使用collection.find(eq(_id3)).first()来查找具有特定_id的首个文档。

3731

被折叠的 条评论
为什么被折叠?



