3.5.1 统计查询
统计查询使用count()方法,语法如下:
db.collection.count(query, options)
(1)统计所有记录数
统计comment集合的所有的记录数:
db.comment.count()
(2)按条件统计记录数
例如:统计userid为1003的记录条数
db.comment.count({userid:"1003"})
提示: 默认情况下 count() 方法返回符合条件的全部记录条数。
3.5.1 统计查询
统计查询使用count()方法,语法如下:
db.collection.count(query, options)
(1)统计所有记录数
统计comment集合的所有的记录数:
db.comment.count()
(2)按条件统计记录数
例如:统计userid为1003的记录条数
db.comment.count({userid:"1003"})
提示: 默认情况下 count() 方法返回符合条件的全部记录条数。