高性能mongodb之利用javascript函数式编程玩转mongodb shell
我的专栏地址:我的segmentfault,欢迎浏览
命令一集合记录数列表: db.getCollectionNames().forEach((name) => {print(name+","+db[name].stats().count)})
快速展示mongo所有集合和集合的文档数,但是没有做排序。
> db.getCollectionNames().forEach((name) => {print(name+","+db[name].stats().count)}) log.login_online,2673475 log.challenge_result,390836 log.order,2674511 log.animal,1534481 log.animal_arrest,1095140
命令二集合按记录条数排序: db.getCollectionNames().map((name) => db[name]).sort((a,b) => {return a.count()-b.count()}).forEach((db) => {print(db.getName()+","+db.count())})
快速展示mongo所有集合和集合的文档数,并排好序。运用知识:map、sort、forEach
>db.getCollectionNames().map((name) => db[name]).sort((a,b) => {return a.count()-b.count()}).forEach((db) => {print(db.getName()+","+db.count())}) log.challenge_result,390836 log.animal_arrest,1095140 log.animal,1534481 log.login_online,2673475 log.order,2674511
相关推荐
Jruing 2020-11-01
89231645 2020-10-26
87204154 2020-09-24
81244053 2020-09-23
FalseNotFalse 2020-09-22
81540398 2020-09-04
84423067 2020-06-12
hongbing 2020-06-02
huavhuahua 2020-05-11
samsai00 2020-05-06
猛禽的编程艺术 2020-04-23
上海滩 2020-04-22
斑点喵 2020-03-04
cuiguanjun 2020-03-01
TheBigBlue 2020-02-20
banzhihuanyu 2020-02-19
banzhihuanyu 2020-02-15
89510196 2020-02-06
banzhihuanyu 2020-01-31