场景:
当想统计mongodb集合的结构是什么数据类型时。
1.利用variety.js解析
https://github.com/variety/variety
2.脚本
#!/bin/bash#user='xxx'
#passw='xxx'
host='1xx.1x.1x.150'
port=27010
db='hgr'tabs=$(echo "show collections"|mongo ${host}:${port}/${db}|grep -vE 'version|not match|session|compressors|=|Warning|delivers|upcoming|installation|https|switched|bye' )for t in $tabs;doecho ' ' && echo '+------------------------------------------+' && echo '|'"${db}.${t}"' |'mongo ${host}:${port}/${db} --eval "var collection = '${t}'" variety.js|grep -vE 'Variety|MongoDB|Implicit|Version|Using|connecting'
done
3.执行效果: