0

from the mongo console how do I export the profile data to a file

when I run this command db.system.profile.find( { millis : { $gt : 20000 } } ).pretty()

How do I get all the data into text file

kumar
  • 8,207
  • 20
  • 85
  • 176
  • Is this useful for you? https://stackoverflow.com/questions/22565231/printing-mongo-query-output-to-a-file-while-in-the-mongo-shell – jusx Jul 30 '20 at 10:34

1 Answers1

0

Depends on your OS. I have run the following on mac.

mongo --quiet --eval "db.system.profile.find( { millis : { $gt : 20000 } } ).pretty()" > dummy.json

--quiet will ignore all the server info which you get at the start

--eval will run the command for you. You can also run script as a js file. Simply remove the --eval and "". And replace it with someScript.js

Yahya
  • 3,386
  • 3
  • 22
  • 40
  • This did not work I got this error in dumm.json 2020-07-30T14:04:45.205+0000 SyntaxError: Unexpected token : . FYI when i try to query the profile "mongo" and then "use ". then run db.system.profile – kumar Jul 30 '20 at 14:12
  • You can also try, "db.getSiblingDB('admin').profile...". Read more details here: https://docs.mongodb.com/manual/tutorial/manage-the-database-profiler/#database-profiler – Yahya Jul 30 '20 at 16:32