[ mongodb ] mongoexport

mongoexport –db test –collection traffic –out traffic.json


–host <hostname><:port>



–query “<json>”

–fields “_id._p,value.count”



mongoexport --host localhost:27017 --username mydbuser --password mydbsecret --db test --collection user --fields "email,updated_at" --query '{"updated_at": {"$gte": ISODate("2017-08-29T09:10:05.280Z")}}' --out user.json


export from all shard

ref : https://www.codejuggle.dj/how-to-backup-and-restore-a-mongodb-sharded-cluster/

[ GoLang ] underscore function

underscore ( _ ) avoids having to declare all the variables for the returns values.


changeInfo, err := c.RemoveAll(query)

This will cause the compile error

$ go build mongo_connect.go
# command-line-arguments
./mongo_connect.go:104: changeInfo declared and not used

So, change it to underscore.

_, err := c.RemoveAll(query)

ref : https://stackoverflow.com/questions/27764421/what-is-in-a-golang-declaration