承接国内外服务器租用托管、定制开发、网站代运营、网站seo优化托管接单、网站代更新,新老站点皆可!!咨询QQ:3787320601
当前位置:首页  >  互联网圈  >  mongodb:mongodb中count如何用

mongodb:mongodb中count如何用

管理员 2023-04-04 11:01:20 互联网圈 44 ℃ 0 评论 2183字 收藏

mongodb中count如何用

mongodb中count的使用方法:在mongodb中对大量的数据,可使用count()方法对数据进行统计,语法格式为:“db.集合名称.find({条件}).count()”和“db.集合名称.count({条件})”,例如:“db.yisu.find({name:{$ne:null}}).count()”统计yisu集合中name字段的数据记录。

mongodb中count怎么用

下面是详细介绍:

一、count()方法介绍

1、作用:用于统计结果集中文档条数

2、count()方法两种使用语法

db.集合名称.find({条件}).count()

db.集合名称.count({条件})

3、返回值

返回一个包括计数和命令状态的文档。

二、count()方法使用实例

> db.foo.find({name:{$ne:null}})

{ "_id" : ObjectId("544db3b45d92133398a80dab"), "a" : 1, "name" : "zzz" }

> db.foo.find({name:{$ne:null}}).count()             #查出个数为1,正确的

1

> db.foo.find({name:{$ne:null}}).skip(2)             #查不出数据

> db.foo.find({name:{$ne:null}}).skip(2).count()      #查出个数为1,不正确

1

> db.foo.find({name:{$ne:null}}).skip(2).count(1)    #查出个数为0,正确

0

出现统计慢的现象,则加上projection便可处理。

db.trip_product.find({"supplierId":{$in:["ziying", "ycf", "dfy"]}, "remove":0},

{"remove":1,"_id":0}).itcount()

文章来源:丸子建站

文章标题:mongodb:mongodb中count如何用

https://www.wanzijz.com/view/6388.html

TAG: mongodb
X

截屏,微信识别二维码

微信号:weimawl

(点击微信号复制,添加好友)

打开微信