有没有办法在MongoDB中的一个查询中获取文档和文档计数?
result = db.collection.find({})
这将返回我们的收集文件。
count = db.collection.count_documents({})
这将返回我们收集中的文件计数。
我想在一个查询中获得文档和文档计数。
有解决方案吗?
result = db.collection.find({})
This will return us documents of collection.
count = db.collection.count_documents({})
This will return us count of documents in collection.
I want to get both of documents and count of documents in one query.
Any solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是使用汇总,
另一种做法是使用第三方模块,例如
mongoose-paginate-v2
,它将为您提供所有数据,并提供简单的查找查询。One way of doing it is to use aggregation,
Another way of doing it is to use third party module like
mongoose-paginate-v2
, it will provide you all the data with your simple find query.