How can I use mongoexport to download device configuration files?
Hi
Thanks for your posts.
You may try to use the built-in plugin to export the configuration files, pls see below:

Hope it helps,
Thanks,
Gerry
This gives me some insight. I have code (below) in bash to do mongoexport of collection ‘Devices’ to get the list of devices. Was hoping to do the same for the config of devices as needed. Can I sftp to the netbrain DB server?
# define the mongodb export
mxcmd="mongoexport"
mxcmd="${mxcmd} --quiet"
mxcmd="${mxcmd} --host=${mongoh}"
mxcmd="${mxcmd} --authenticationDatabase=${mongod}"
mxcmd="${mxcmd} --authenticationMechanism=SCRAM-SHA-1"
mxcmd="${mxcmd} --username=${mongou}"
mxcmd="${mxcmd} --password=${mongop}"
mxcmd="${mxcmd} --db=${mongod}"
mxcmd="${mxcmd} --collection=${mongoc}"
# do the mongodb export, parse with jq
${mxcmd} | ${jqcmd}
For the Mongodb commands, assuming the default username is admin and password is Admin1.#, connect to database admin:
Login Mongodb without SSL
# mongo -u admin -p Admin1.# --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256
Login Mongodb with SSL
# mongo -u admin -p Admin1.# -ssl --sslAllowInvalidCertificates --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-256
Thanks
I am able to authenticate properly using mongoexport and get device details from the ‘Devices’ collection. I am having issues finding the proper collection(s) for exporting device configs.
The config is in your domain database>DeviceDataCurr, type = config, see below:

Outstanding. Using mongoexport with ‘--collection=DeviceDataCurr’ gives me the configs for all devices. Looks like I need to include a query filter for the specific device ID or name. I’ll google that next.
{
"_id": "968349f8-1446-4ad8-b731-84b2458bdd48",
"content": "na-us-271-nashville-srv01#show run all\r\r\n\r\n!Command: show running-config...
"contentType": "text/plain",
"devId": "2ff1b68b-72b1-40fc-ad36-6059494ee356",
"devName": "na-us-271-nashville-srv01",
"length": 129575,
"md5": "e57fc83a2e24b64f6ce7ae1784881786",
"operateInfo": {
"opTime": {
"$date": "2019-05-29T05:18:03Z"
},
"opUser": "admin"
},
"sourceId": "145a4a67-ed99-4742-8411-3220966bb65c",
"sourceType": "benchmark task",
"type": "config",
"uploadDate": {
"$date": "2025-02-19T07:53:28Z"
},
"name": "",
"subName": null
}
Thanks for all your help.
mongoexport --host=${mongoh} --authenticationDatabase=${mongod} --authenticationMechanism=SCRAM-SHA-1 --username=${mongou} --password=${mongop} --db=${mongod} --collection=${mongoc} --query '{"devName":"na-us-271-nashville-srv01","type":"config"}' --type=csv --fields=content
Reply
Login to the community
No account yet? Create an account
Sign in with SSO
Login via NetBrain UniversityEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.