简体   繁体   English

在MongoDB中如何知道它是否是集合的最后一条记录?

[英]In MongoDB how to know if it is the last record of a collection?

How to know if I'm returning the last set of document/documents of a collection?如何知道我是否返回了集合的最后一组文档/文档?

For now I keep the full document count as reference to check if I received the all the records.现在我保留完整的文档计数作为参考,以检查我是否收到了所有记录。

I'm using skip with limit for lazy loading.我正在使用skip with limit进行延迟加载。 Is there a better way to do this ?有一个更好的方法吗 ?

You can, as confirmed by @Abhishek Anand你可以,正如@Abhishek Anand 所证实的那样

  • count +计数 +
  • skip,limit跳过,限制

You can also fetch limit+1 documents, and only return min(n documents found, limit) This way you avoid a count, and you know you reached the end of collection whenever you don't have limit+1 documents found您还可以获取 limit+1 个文档,并且只返回min(n documents found, limit)这样您就可以避免计数,并且当您没有找到limit+1 documents found时,您就知道到达了集合的末尾

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM