温馨提示×

mongodb查询记录数的方法是什么

小亿
117
2024-05-28 09:55:06
栏目: 云计算

要查询 MongoDB 中的记录数,可以使用以下方法之一:

  1. 使用 count() 方法:
db.collectionName.count()
  1. 使用 countDocuments() 方法(推荐):
db.collectionName.countDocuments()

这两种方法都可以用来获取指定集合中的记录数。请记住,MongoDB 从版本 4.0 开始,count() 方法已被弃用,建议使用 countDocuments() 方法。

0