阅读量:125
要查询 MongoDB 中的记录数,可以使用以下方法之一:
- 使用
count()方法:
db.collectionName.count()
- 使用
countDocuments()方法(推荐):
db.collectionName.countDocuments()
这两种方法都可以用来获取指定集合中的记录数。请记住,MongoDB 从版本 4.0 开始,count() 方法已被弃用,建议使用 countDocuments() 方法。