0

Suppose I have ssh access to a server with mongodb on it. However, suppose the server does not have mongoexport installed, and I cannot install it. I can use mongo, interactively or feed it a script. I wish to export a subset of the data and import it on my local computer. Ideally, I'd like to run a script or command that saves the data in the same format as mongoexport, so I can import it with mongoimport locally. https://stackoverflow.com/a/12830385/513038 doesn't work (as it has extra line breaks in the results), nor does using printjsononeline instead, because some values get printed differently and I end up with "Bad characters" and "expecting number" errors when I run mongoimport.

Any ideas? Again, I'd like to use mongoimport if possible, but other sufficiently workable ways are acceptable, as well.

Community
  • 1
  • 1
Erhannis
  • 4,256
  • 4
  • 34
  • 48
  • If you are trying to export a collection, probably this may help http://stackoverflow.com/questions/8971151/file-write-operations-in-mongo-script – Abhi Dec 05 '14 at 16:51
  • @Abhi Thanks, but `printjson` doesn't work, or at least I don't know how to import the results, anyway. – Erhannis Dec 05 '14 at 20:48
  • Can you transfer files? It would be easier to transfer the data files. To transfer them directly, the mongod should be stopped, but you can also use mongodump to create a BSON dump and transfer that. Using mongodump/mongorestore is preferable to mongoimport/mongoexport because the latter has JSON as the intermediate format, which is not as type-rich as BSON and so can lose type information. – wdberkeley Dec 08 '14 at 16:26
  • @wdberkeley Unfortunately, the server ALSO doesn't have `mongodump`. It only has `mongo`, `mongo_console`, and `mongos`. Furthermore, it looks like the database is 300+ GB big, and it'd probably be a security hazard for me to have a full copy of it, anyway. In any case, I eventually just manually copied some data over w/copy-paste, so I don't really need an answer anymore, though it'd probably come in handy in the future. – Erhannis Dec 09 '14 at 20:39

0 Answers0